4.4 Writing the VBA code

In the “Click” event handler of the “Update SendCard” button, specify the following code:

1Dim myRecordSet as RecordSet  
2Set myRecordSet = CurrentDB.OpenRecordSet(”Contacts”, dbOpenDynaset)   
3myRecordSet.MoveFirst  
4Do While Not myRecordSet.EOF  
5  myRecordSet.Edit  
6  If (MsgBox(”Send_card_to_” & _   
7             myRecordSet![First Name] & ”_” & _ 
8             myRecordSet![Last Name] & ”?”, _ 
9             vbYesNo) = vbYes) then 
10    myRecordSet![SendCard] = 1 
11  Else 
12    myRecordSet![SendCard] = 0 
13  End If   
14  myRecordSet.Update  
15  myRecordSet.MoveNext  
16Loop 

The following is the overall explanation of the code:

A lot of mystery is in the conditional statement itself, so it deserves some further explanations: