I've been trying to create a search form in access for a while now, searching through books and emails. I have the search form set up with 11 combo box's, 3 text box's, a view button, and a clear button. Once the user enters certain fields, all of the boxes do not have to be filled and clicks the view button, a report will pop up with detail of what was found.I found this code (http://bytes.com/topic/access/answers/879487-question-about-form) and modified it for my needs. I tested the code and i got it to work for 2 text boxes, when i changed it to combo boxes, i received an error.
So, my question is, how to i complete what needs to be done. I know I'm at the beginning but i need to get this done.
Expand|Select|Wrap|Line Numbers
- Dim strStudentRef As String
- Dim strSearch As String
- Dim strSql As String
- 'Check Search Form for Null value or Nill Entry first.
- If IsNull(Me![cmboOB]) Or (Me![cmboOB]) = Null Then
- If IsNull(Me![cmboCN]) Or (Me![cmboCN]) = Null Then
- MsgBox "Nothing Entered!", vbOKOnly, "Blank!"
- Me![cmboOB].SetFocus
- Exit Sub
- End If
- End If
- '---------------------------------------------------------------
- 'Performs the search using value entered into txtSearch
- 'and evaluates this against values in Address
- DoCmd.ShowAllRecords
- 'Chr(42)is ascii code for the wildcard symbol
- strSql = "Select * from [tblDocument] Where |related field for cmboOB| & |related field for cmboCN| Like '" & Chr(42) & Me!cmboOB & Me!cmboCN & Chr(42) & "';"
- Me.RecordSource = strSql
- 'If one or more matching records are found, they can be displayed one at a time via the navigation buttons
- If Me.Recordset.RecordCount > 0 Then
- cmboOB.SetFocus
- strSearch = cmboOB.Text
- cmboOB.SetFocus
- strSearch = cmboOB & Space(1) & cmboCN
- MsgBox "Match Found For: " & strSearch & " ", _
- , "Found!"
- cmboOB.SetFocus
- cmboOB = Null
- cmboCN = Null
- 'If value not found sets focus back to txtSearch and shows msgbox
- Else
- cmboOB.SetFocus
- strSearch = cmboOB & Space(1) & cmboCN
- MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
- , "Sorry"
- cmboOB.SetFocus
- End If
- End Sub