Help Needed: Run combo row source query

N

niuginikiwi

Hi helpers,
I have a combo box on the subform (Datasheet View) and get its data from a
saved query.
I have a button on the main form that opens an unbound form where I select a
criteria from the list box and when I click OK on the unbound form, I want
the SQL string behind the Onclick event to fire and run the query behind the
combo on subform of that other form.

Here is the SQL string on the OK button

Private Sub btnOK_Click()

Dim lst As ListBox
Dim strWhere As String
Dim iLen As Integer


'GrowerName List
Set lst = Me.lstCrops
If Not IsNull(lst) Then
strWhere = strWhere & "(CropName = """ & lst.Column(1) & """) AND "
End If


'Similar for other list, combo or text boxes here.

'Did we get anything?
iLen = Len(strWhere) - 5 'Without trailing " AND ".
If iLen < 1 Then
MsgBox "Sorry! MUST select a Crop", vbInformation, "Pedro Says..."
Else
strWhere = Left$(strWhere, iLen)

'Use it for this form.
Me.Filter = strWhere
Me.FilterOn = True

'Run the query and apply filter.
'I THINK I HAVE TO PUT SOMETHING HERE TO RUN THE QUERY

End If

Set lst = Nothing
End Sub

Any help would be much appreciated.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top