Quote:
Originally Posted by Newbie2VB
When I run my code, I get this "object variable or with block variable not set" error message.
-
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