object variable or with block variable not set error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Newbie2VB
    New Member
    • Jul 2008
    • 2

    #1

    object variable or with block variable not set error

    When I run my code, I get this "object variable or with block variable not set" error message.

    Code:
    Public Function fGetHeaderList() As String
    Dim strList(5) As CheckBox
    Dim i As Integer
        
        fGetHeaderList = "SELECT "
        strList(0) = "A"
        strList(1) = "B"
        strList(2) = "C"
        strList(3) = "D"
        strList(4) = "E"
        strList(5) = "F"
          
        For i = LBound(strList) To UBound(strList)
            
            If (i = 5 And strList(i).Value) Then 
            
                fGetHeaderList = fGetHeaderList + "table1." + strList(5)
            Else
            
                If (strList(i).Value) Then
                    fGetHeaderList = fGetHeaderList + "table1." + strList(i) + ", "
                End If
                
            End If
            
        Next
        
        If (fGetHeaderList <> "SELECT ") Then
            
            fGetHeaderList = fGetHeaderList + " FROM table1 INNER JOIN table2 ON table1.A = table2.key"
        End If
    End Function
    A, B, C, D, E, F are the names of the existing check boxes on the form. I'm trying to access it using array in this function.
    Can anyone please help me to solve this problem. I'm thinking it's about my object reference problem. And I'm new to VB.

    Thanks so much.
    Last edited by Newbie2VB; Jul 15 '08, 01:39 PM. Reason: more details
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Originally posted by Newbie2VB
    When I run my code, I get this "object variable or with block variable not set" error message.

    Code:
    Public Function fGetHeaderList() As String
    Dim strList(5) As CheckBox
    Dim i As Integer
        
        fGetHeaderList = "SELECT "
        strList(0) = "A"
        strList(1) = "B"
        strList(2) = "C"
        strList(3) = "D"
        strList(4) = "E"
        strList(5) = "F"
          
        For i = LBound(strList) To UBound(strList)
            
            If (i = 5 And strList(i).Value) Then 
            
                fGetHeaderList = fGetHeaderList + "table1." + strList(5)
            Else
            
                If (strList(i).Value) Then
                    fGetHeaderList = fGetHeaderList + "table1." + strList(i) + ", "
                End If
                
            End If
            
        Next
        
        If (fGetHeaderList <> "SELECT ") Then
            
            fGetHeaderList = fGetHeaderList + " FROM table1 INNER JOIN table2 ON table1.A = table2.key"
        End If
    End Function
    A, B, C, D, E, F are the names of the existing check boxes on the form. I'm trying to access it using array in this function.
    Can anyone please help me to solve this problem. I'm thinking it's about my object reference problem. And I'm new to VB.

    Thanks so much.
    Hi

    As its an array of Checkbox OBJECT I think the array initialization this should be like

    set strList(0) = Me.A
    set strList(1) = Me.B
    or
    Set strList(0) = A
    Set strList(1) = B

    etc

    Assuming the checkboxes are actually named A, B, .. etc

    This is also assuming that code is in the code module of the form containing the checkboxes?
    If not the you need to qualify the form as well (which must be open).

    ie Set strList(0) = Form_Your FormName.A


    MTB

    Comment

    • Newbie2VB
      New Member
      • Jul 2008
      • 2

      #3
      Thank you so much. problem solved

      Comment

      Working...