T
Tony Williams
I have a search form that uses an unbound list box there is a text box that
is used to filter three fields in three tables and I've tried to add a date
range function. Here is the SQL of the list box query
SELECT tblInstitution1.txtRefNbr, tbldocument.txtExpirydate,
tblInstitution1.txtInstitution, tblInstitution1.txtfirstname & " " &
tblInstitution1.txtlastname AS [Contact 1], tblInstitution2.txtInstitution2,
tblInstitution2.txtFirstname & " " & tblInstitution2.txtlastname AS [Contact
2], tblInstitution3.txtInstitution3, tblInstitution3.txtFirstname & " " &
tblInstitution3.txtlastname AS [Contact 3]
FROM ((tbldocument INNER JOIN tblInstitution2 ON tbldocument.txtRefNbr =
tblInstitution2.txtRefNbr) INNER JOIN tblInstitution1 ON
tbldocument.txtRefNbr = tblInstitution1.txtRefNbr) INNER JOIN
tblInstitution3 ON tbldocument.txtRefNbr = tblInstitution3.txtRefNbr
WHERE (((tblInstitution1.txtlastname) Like [Forms]![frmsearch3]![txtname] &
"*")) OR (((tblInstitution2.txtlastname) Like [Forms]![frmsearch3]![txtname]
& "*")) OR (((tblInstitution3.txtlastname) Like
[Forms]![frmsearch3]![txtname] & "*"))
ORDER BY tblInstitution1.txtInstitution;
The code for the Ondoubleclick of my list box is
Private Sub List3_DblClick(Cancel As Integer)
Dim strWhere As String
Dim strWhere2 As String
Dim StrWhere3 As String
Dim strField As String
strField = "[tbldocument].[txtExpirydate]"
If IsNull(Me.txtname) Then
MsgBox "You must enter some text in the box to filter the records", vbOKOnly
End If
If IsNull(Me.txtstartdate) Then
If Not IsNull(Me.txtenddate) Then
strWhere = strField & " <= " & (Me.txtenddate)
End If
Else
If IsNull(Me.txtenddate) Then
strWhere = strField & " >= " & (Me.txtstartdate)
Else
strWhere = strField & " Between " & (Me.txtstartdate) & " AND " &
(Me.txtenddate)
End If
End If
strWhere2 = "[tblInstitution1].[txtRefNbr]=" & Me.[List3]
StrWhere3 = "strWhere" & "stWhere2"
DoCmd.OpenForm "frmMdi", , , strWhere3
End Sub
The code filters the list box with the strWhere2 line but the strWhere
doesn't work I get a prompt box asking me what it is and the form opens to a
new record. Am I going about this is the right way? How do I combine the two
strings to use them both to open the form?
Thanks as ever
Tony
is used to filter three fields in three tables and I've tried to add a date
range function. Here is the SQL of the list box query
SELECT tblInstitution1.txtRefNbr, tbldocument.txtExpirydate,
tblInstitution1.txtInstitution, tblInstitution1.txtfirstname & " " &
tblInstitution1.txtlastname AS [Contact 1], tblInstitution2.txtInstitution2,
tblInstitution2.txtFirstname & " " & tblInstitution2.txtlastname AS [Contact
2], tblInstitution3.txtInstitution3, tblInstitution3.txtFirstname & " " &
tblInstitution3.txtlastname AS [Contact 3]
FROM ((tbldocument INNER JOIN tblInstitution2 ON tbldocument.txtRefNbr =
tblInstitution2.txtRefNbr) INNER JOIN tblInstitution1 ON
tbldocument.txtRefNbr = tblInstitution1.txtRefNbr) INNER JOIN
tblInstitution3 ON tbldocument.txtRefNbr = tblInstitution3.txtRefNbr
WHERE (((tblInstitution1.txtlastname) Like [Forms]![frmsearch3]![txtname] &
"*")) OR (((tblInstitution2.txtlastname) Like [Forms]![frmsearch3]![txtname]
& "*")) OR (((tblInstitution3.txtlastname) Like
[Forms]![frmsearch3]![txtname] & "*"))
ORDER BY tblInstitution1.txtInstitution;
The code for the Ondoubleclick of my list box is
Private Sub List3_DblClick(Cancel As Integer)
Dim strWhere As String
Dim strWhere2 As String
Dim StrWhere3 As String
Dim strField As String
strField = "[tbldocument].[txtExpirydate]"
If IsNull(Me.txtname) Then
MsgBox "You must enter some text in the box to filter the records", vbOKOnly
End If
If IsNull(Me.txtstartdate) Then
If Not IsNull(Me.txtenddate) Then
strWhere = strField & " <= " & (Me.txtenddate)
End If
Else
If IsNull(Me.txtenddate) Then
strWhere = strField & " >= " & (Me.txtstartdate)
Else
strWhere = strField & " Between " & (Me.txtstartdate) & " AND " &
(Me.txtenddate)
End If
End If
strWhere2 = "[tblInstitution1].[txtRefNbr]=" & Me.[List3]
StrWhere3 = "strWhere" & "stWhere2"
DoCmd.OpenForm "frmMdi", , , strWhere3
End Sub
The code filters the list box with the strWhere2 line but the strWhere
doesn't work I get a prompt box asking me what it is and the form opens to a
new record. Am I going about this is the right way? How do I combine the two
strings to use them both to open the form?
Thanks as ever
Tony