list search results in listbox on form to select

H

hawkins.devin

I'm trying to list search results in the same form that I have the
keyword search. It's more of an advanced search functionality as where
the user selects what field name they want to search by then enters a
key word.

Below is vba code that the frmSearch filters the frmCustomers by rather
than display the search results on frmSearch like I want. I created a
list box on frmSearch to display the search results if I can get it to
work. It would then filter the frmCustomers based on what search result
I select in the list box.

Any suggestions would be great!

----------------------------------------------------------VBA
Code--------------------------------------------------------------

Option Compare Database

Private Sub cmdClose_Click()

'Close form
DoCmd.Close

End Sub

Private Sub cboSearchField_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub cmdSearch_Click()

If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."

ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True
Then
MsgBox "You must enter a search string."

Else

'Generate search criteria
GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString
& "*'"

'Filter frmCustomers based on search criteria
Form_frmCustomers.RecordSource = "select * from Customers where
" & GCriteria
Form_frmCustomers.Caption = "Customers (" &
cboSearchField.Value & " contains '*" & txtSearchString & "*')"

'Close frmSearch
'DoCmd.Close acForm, "frmSearch"

'MsgBox "Results have been filtered."

End If

End Sub


----------------------------------------------------------End VBA
Code-------------------------------------------------------
 

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