Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding items to a ListBox

Status
Not open for further replies.

ActMod

Technical User
Aug 25, 2003
45
US
Can someone help me debug the below code?
The code works until I get to the line "lstClaims.AddItem Qrys.Name", at which point I get an error message stating "Object Variable or With Block Variable not set".

A ListBox named lstClaims resides on the Form named "frmQry".

Thank you for any help.

Jim



Dim lstClaims As ListBox

Dim Qrys As Object

DoCmd.OpenForm "frmQry"
With CurrentData
For Each Qrys In .AllQueries
If Qrys.Name = "qryClaims" Then
lstClaims.AddItem Qrys.Name

End If
Next Qrys
End With

 
Thanks vbajock, but I tried Qrys![Name] and got the same error message.

Jim


 
my bad. Here's your real problem:
Dim Qrys As Object

You don't have any code that sets this object to anything. Example
Set Qrys=CreateObject(somkindaobject)
 
Please parden my ignorance, but I don't know what to put as "somekindaobject"? I am using "Qrys" as a variable object to sort thru all the Querys in my project.

The first half of the macro's "If Statement" does work:

If Qrys.Name = "qryClaims" Then
lstClaims.AddItem Qrys.Name
end if

That is, the macro does find the Query named "qryClaims". I get the error when the name is supposed to be added to the ListBox named "lstClaims". My problem seems to be the "Then" part of the "If Statement".

Any suggestions? Thanks much again for your help.

Jim
 
It's a little more complicated than what you are coding. You should look under the "QueryDefs" section of the Help file, I think that has some example code on how to loop thru the QueryDef objects in your database
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top