View Full Version : Enter Query Criteria from Form


Jeff.Nolan
12-10-2007, 12:14 PM
Here is the code I have:

Private Sub CmbGenerate_Click()
Dim MyDB As DAO.Database
Dim qdef As DAO.QueryDef
Dim i As Integer
Dim strWhere As String
Dim strIN As String
Dim varItem As Variant

Set MyDB = CurrentDb()

'Build the IN string by looping through the listbox
For i = 0 To lstENTITYNAME.ListCount - 1
If lstENTITYNAME.Selected(i) Then
strIN = strIN & "'" & lstENTITYNAME.Column(0, i) & "',"
End If
Next i

'Create the WHERE string, and strip off the last comma of the IN string
strWhere = "in (" & Left(strIN, Len(strIN) - 1) & ")"

Set qdef = MyDB.QueryDefs![MainQuery]
qdef.Parameters![ENTITY SETS]![ENTITY SET NAME] = strWhere

DoCmd.OpenQuery "MainQuery", acViewNormal


End Sub


The problem I am having is with these 2 lines.
Set qdef = MyDB.QueryDefs![MainQuery]
qdef.Parameters![ENTITY SETS]![ENTITY SET NAME] = strWhere

I am trying to get the info from strWhere to be sent to a query I have called "MainQuery" in the criteria field ENTITY SET NAME, which is from the table ENTITY SETS

Any help would be great.
Thanks so much.

MStef
12-11-2007, 12:37 AM
Look at "DemoLBInQryA2000.mdb",
look at Table1, queries, Form2 (VBA), report.
Open Form2 and try.

Jeff.Nolan
12-11-2007, 06:50 AM
Thanks for you help.
This is perfect. After a couple hours of tweaking, it works perfectly.

jeff