Thread: Object required
View Single Post
  #2 (permalink)  
Old November 9th, 2007, 03:32 PM
BrianWren BrianWren is offline
Friend of Wrox
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts

I don't know where this way of doing things originated, but I personally find it out of keeping with consistency.

All statements within a block typically are indented. The Sub/End Sub statements delineate a block. Yet so many people don't indent the On Error statement, and many also don't indent the Dim statements.

Your comment, ' Declares the Object Varibles (sic) only states the obvious. Think about removing the comment. The same with the ' Sets . . . statments.
Try to avoid “Magic Number” statements like If Rst.State = 1 ... Use the predefined constants (adStateOpen).
PopulateControlsOnForm is a sub. Don't use Call.
    If Rst.BOF And Rst.EOF Then
        Exit Sub
    Else ' This else is unnecesary.  If the If were true, 
         ' you have already left the Sub.  All after that
         ' is a de facto else...
        Rst.MoveFirst   ' This is unnecesary.  RecSets open to 1st.
    End If

    If Rst.BOF And Rst.EOF Then Exit Sub

    Call PopulateControlsOnForm
    Rst has local scope only within Sub Form_Load().

Do this:
    PopulateControlsOnForm Rst

Sub PopulateControlsOnForm(ByRef Rst As ADODB.Recordset)

Reply With Quote