Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Visual Basic (Classic) FAQ

VB Programming Concepts

Using Data Control at Form_Load() by phinoppix
Posted: 29 Jul 02

One common problem for most DBMS developers is fetching record via data control before the form becomes visible and initialize the appropriate controls with that record.

It's been "customary" for most programmers to initialize data control at Form_Load(), but errors usually follow. One reason is that the connection properties will take effect after the data control is completely painted in the form, that is, after Form_Load(), or at Form_Activate().

With these FAQs in mind, one could then use any of the following methods to resolve this problem.

***** This portion applies to VB's intrinsic data control ****

1) Initialize the Data control at Form_Load, but fetch at Form_Activate().
    Take into consideration switches to ensure that initialization takes place only once since Form_Activate()will be raised very often esp. when switching windows.
        Private Sub Form_Activate()
            Static sw as Boolean
            If Not sw Then
                With daoctrl.Recordset
                    Text1.Text = .Fields(0)
                End With
            End If
        End Sub

        Private Sub Form_Load()
            With daoctrl
                .Databasename = "DBPath"
                .Recordsource = "rcdSource"
            End With
        End Sub

2. Execute Refresh method immediately
        Private Sub Form_Load()
            With daoctrl
                .Databasename = "DBPath"
                .Recordsource = "rcdSource"
                Text1.Text = .Recordset.Fields(0)
            End With
        End Sub

***** This portion applies to ADO data control ****

ADO data control's design is most practical like for this matter. ADO data control remains disabled on any form events even if all connection properties were defined until the Refresh method is executed, similar to method #2.

Back to Visual Basic (Classic) FAQ Index
Back to Visual Basic (Classic) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close