Freetutes.com

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 8

Sponsored Links

Programmatically Reading a Record's Contents Into VB Controls

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.

<< Previous | Contents | Next >>

 

 

Home | Link to Us | Partner Links | About Us | Contact Us
Copyright © 2007-2008 Freetutes.com | All Rights Reserved