Typically, you will write a procedure such as that of Listing 8.4 to populate
controls with field contents from a Recordset. You will call such a routine from
every place in your application that potentially updates the record pointer.
The MoveComplete event procedure is often the best place from which to call such
code.
LISTING 8.4
ROUTINE TO POPULATE CONTROLS FROM COPY BUFFER
Sub PlaceDataInControls()
txtFirstName.Text = rsEmployees![First Name]
& ""
txtLastName.Text = rsEmployees![Last Name] &
""
txtDepartment.Text = rsEmployees!Department
& ""
txtPhoneExt.Text = rsEmployees!PhoneExt &
""
'assumes field will contain a valid
'CheckBox value (0, 1, or 2)
chkFullTime.Value = rsEmployees![Full Time]
End Sub
As an alternative to the use of the & "" characters, you
could also trap null data more explicitly with code such as that shown in Listing 8.5.
LISTING 8.5
LOGIC TO EXPLICITLY TEST FOR NULL DATA
If IsNull(txtFirstName.Text) Then
txtFirstName.Text = rsEmployees![First Name]
Else
txtFirstName.Text = "<<NULL>>"
End If
Notice, however, that this second method requires you to write several lines
of code, as opposed to just appending & "" to the field contents.