I'm currently implementing a container monitoring system in MSAccess07 and I'm using a multiple search function to sort containers. I use several unbound text boxes and a list box.The user type's in partial search criteria in one or several text boxes. Or if they don't key in anything it returns all records. The matches are returned in a listbox.
I will show the code for 1 text box just to show how it works.
This is the code for the search button:
Expand|Select|Wrap|Line Numbers
- Private Sub cmdShowCont_Click()
- Dim MySQL As String, mycriteria As String, MyRecordSource As String
- Dim argcount As Integer
- Dim Tmp As Variant
- mycriteria = " "
- argcount = 0
- MySQL = "SELECT * FROM qryContLife WHERE "
- Addwtf [textbox], "[Arrival Date]", mycriteria, argcount, "textbox"
- Debug.Print mycriteria
- If mycriteria = " " Then
- mycriteria = "True"
- End If
- MyRecordSource = MySQL & mycriteria
- Me![listbox].RowSource = MyRecordSource
- If Me![listbox].ListCount = 0 Then
- MsgBox " There are no containers with this criteria. Sorry ", 48
- Me!cmdClear.SetFocus
- Else
- Me![listbox].SetFocus
- End If
- End Sub
Expand|Select|Wrap|Line Numbers
- Private Sub Addwtf(fieldvalue As Variant, fieldname As String, mycriteria As String, argcount As Integer, fieldo As String)
- Dim wtf1 As String, wtf2, wtf3 As String
- If fieldvalue <> "" Then
- If argcount > 0 Then
- mycriteria = mycriteria & " and "
- End If
- Select Case fieldo
- Case "textbox"
- wtf2 = Mid$(fieldvalue, 4, 2) & "/" & Mid$(fieldvalue, 1, 2) & "/" & Mid$(fieldvalue, 7, 4)
- mycriteria = (mycriteria & fieldname & " = " & Chr(35) & wtf2 & Chr(35))
- argcount = argcount + 1
- End If
- End Sub
I hope I explained everything in a clear matter, if not please ask questions and I will try and make it more clear.
Thank you for spending your time of somebody else's problems.
Best regards, Eugene.