View Full Version : I need some help on a search/filter form


RossWindows
02-27-2008, 10:13 AM
Hi folks. I have started getting back into Access at work. It's been at least 3 or 4 years. The company I am building this db for is using '97.

I am trying to build a form with a search button and a text box to type a search string.
The form also has a subform which will display or filter the records based on the search criteria

I have tried to adapt "themightydude's" code to work, but i'm not getting anywhere...

I am truly trying to get back into the programming mindset, but have a "writer's block" at this moment.

I really want to understand how VB works. (& Sadly, I know it's one of the easiest languages to understand...)

here's what i have so far.

Private Sub Search_Click()

Dim GCriteria As String

If Len(cboSearchBy) = 0 Or IsNull(cboSearchBy) = 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 = cboSearchBy.Value & " LIKE '*" & txtSearchString & "*'"

'Filter frmCustomers based on search criteria
Form_GlobalSearch.GlobalSearchSub.Form.RecordSourc e = "select * from projects where " & GCriteria
Form_GlobalSearch.Caption = "projects (" & cboSearchBy.Value & " contains '*" & txtSearchString & "*')"

MsgBox "Results have been filtered."

End If

End Sub

I have also attached a picture of the search form and a copy of the db for reference.

Sorry, I know this code is probably WAY off. Any help is greatly appreciated.
Thank you all for your help!

RossWindows
02-27-2008, 12:57 PM
I tried to start over and rethink the way this would work logically and came up with this method: The only problem is; I'm not familiar with how to actually code this.

If cboSearchBy.Value = null or "0"
Then return an error message

ElseIf txtSearchString.Value = null or "0"
Then return an error message

ElseIf cboSearchBy.Value = "Request #"
Then filter GlobalSearchSub for the "ID" field using txtSearchString.Value

ElseIf cboSearchBy.Value = "Request Type"
Then filter GlobalSearchSub for the "RequestType" field using txtSearchString.Value

ElseIf cboSearchBy.Value = "First Name"
Then filter GlobalSearchSub for the "ShipFirstName" field using txtSearchString.Value

End If

'and I would continue the elseif statements for the rest of the possible selections in cboSearchBy

RossWindows
02-29-2008, 09:11 AM
Anybody???