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
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