Connecting Tech Pros Worldwide Forums | Help | Site Map

object variable or with block variable not set error

Newbie
 
Join Date: Jul 2008
Posts: 2
#1: Jul 15 '08
When I run my code, I get this "object variable or with block variable not set" error message.

Expand|Select|Wrap|Line Numbers
  1. Public Function fGetHeaderList() As String
  2. Dim strList(5) As CheckBox
  3. Dim i As Integer
  4.  
  5.     fGetHeaderList = "SELECT "
  6.     strList(0) = "A"
  7.     strList(1) = "B"
  8.     strList(2) = "C"
  9.     strList(3) = "D"
  10.     strList(4) = "E"
  11.     strList(5) = "F"
  12.  
  13.     For i = LBound(strList) To UBound(strList)
  14.  
  15.         If (i = 5 And strList(i).Value) Then 
  16.  
  17.             fGetHeaderList = fGetHeaderList + "table1." + strList(5)
  18.         Else
  19.  
  20.             If (strList(i).Value) Then
  21.                 fGetHeaderList = fGetHeaderList + "table1." + strList(i) + ", "
  22.             End If
  23.  
  24.         End If
  25.  
  26.     Next
  27.  
  28.     If (fGetHeaderList <> "SELECT ") Then
  29.  
  30.         fGetHeaderList = fGetHeaderList + " FROM table1 INNER JOIN table2 ON table1.A = table2.key"
  31.     End If
  32. End Function
  33.  
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.

Expert
 
Join Date: Jun 2007
Location: Derbyshire, UK
Posts: 347
#2: Jul 15 '08

re: object variable or with block variable not set error


Quote:

Originally Posted by Newbie2VB

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

Expand|Select|Wrap|Line Numbers
  1. Public Function fGetHeaderList() As String
  2. Dim strList(5) As CheckBox
  3. Dim i As Integer
  4.  
  5.     fGetHeaderList = "SELECT "
  6.     strList(0) = "A"
  7.     strList(1) = "B"
  8.     strList(2) = "C"
  9.     strList(3) = "D"
  10.     strList(4) = "E"
  11.     strList(5) = "F"
  12.  
  13.     For i = LBound(strList) To UBound(strList)
  14.  
  15.         If (i = 5 And strList(i).Value) Then 
  16.  
  17.             fGetHeaderList = fGetHeaderList + "table1." + strList(5)
  18.         Else
  19.  
  20.             If (strList(i).Value) Then
  21.                 fGetHeaderList = fGetHeaderList + "table1." + strList(i) + ", "
  22.             End If
  23.  
  24.         End If
  25.  
  26.     Next
  27.  
  28.     If (fGetHeaderList <> "SELECT ") Then
  29.  
  30.         fGetHeaderList = fGetHeaderList + " FROM table1 INNER JOIN table2 ON table1.A = table2.key"
  31.     End If
  32. End Function
  33.  
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
Newbie
 
Join Date: Jul 2008
Posts: 2
#3: Jul 16 '08

re: object variable or with block variable not set error


Thank you so much. problem solved
Reply