G
Greg Snidow
Greetings all. I found many posts with suggestions to my need, but for some
reason none of them work for me. I have a form with five unbound text and
combo boxes that populate a list box when a button is hit,from which I would
like the user to be able to double click a record and open frmJobInfo to the
record selected in the list box.
'Set the Dimensions of the Module
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
'Constant Select statement for the RowSource
strSQL = "SELECT tbljob_info.Region, tbljob_info.CO, tbljob_info.RTE,
tbljob_info.[F1/F2], tbljob_info.EWO " & _
"FROM tbljob_info"
strWhere = "WHERE"
strOrder = "ORDER BY tbljob_info.EWO;"
'Set the WHERE clause for the Listbox RowSource if information has been
entered into a field on the form
If Not IsNull(Me.cboRegion) Then '<--If the textbox txtRegion contains no
data THEN do nothing
strWhere = strWhere & " (tbljob_info.Region) Like '*" & Me.cboRegion & "*'
AND" '<--otherwise, apply the LIKE statment to the QueryDef
End If
If Not IsNull(Me.txtCO) Then
strWhere = strWhere & " (tbljob_info.CO) Like '*" & Me.txtCO & "*' AND"
End If
If Not IsNull(Me.txtRte) Then
strWhere = strWhere & " (tbljob_info.RTE) Like '*" & Me.txtRte & "*' AND"
End If
If Not IsNull(Me.cboF1F2) Then
strWhere = strWhere & " (tbljob_info.[F1/F2]) Like '*" & Me.cboF1F2 & "*'
AND"
End If
If Not IsNull(Me.txtEWO) Then
strWhere = strWhere & " (tbljob_info.EWO) Like '*" & Me.txtEWO & "*' AND"
End If
'Remove the last AND from the SQL statment
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)
'Pass the SQL to the RowSource of the listbox
Me.lstJobInfo.RowSource = strSQL & " " & strWhere & "" & strOrder
End Sub.
I copied the code from an Access tips website, and just changed the names.
It works great in acting as a filter to populate the list box, but the code
for the double click event of the list box does not work. Does anyone know
how to make this work for me? Thanks in advance.
reason none of them work for me. I have a form with five unbound text and
combo boxes that populate a list box when a button is hit,from which I would
like the user to be able to double click a record and open frmJobInfo to the
record selected in the list box.
'Set the Dimensions of the Module
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
'Constant Select statement for the RowSource
strSQL = "SELECT tbljob_info.Region, tbljob_info.CO, tbljob_info.RTE,
tbljob_info.[F1/F2], tbljob_info.EWO " & _
"FROM tbljob_info"
strWhere = "WHERE"
strOrder = "ORDER BY tbljob_info.EWO;"
'Set the WHERE clause for the Listbox RowSource if information has been
entered into a field on the form
If Not IsNull(Me.cboRegion) Then '<--If the textbox txtRegion contains no
data THEN do nothing
strWhere = strWhere & " (tbljob_info.Region) Like '*" & Me.cboRegion & "*'
AND" '<--otherwise, apply the LIKE statment to the QueryDef
End If
If Not IsNull(Me.txtCO) Then
strWhere = strWhere & " (tbljob_info.CO) Like '*" & Me.txtCO & "*' AND"
End If
If Not IsNull(Me.txtRte) Then
strWhere = strWhere & " (tbljob_info.RTE) Like '*" & Me.txtRte & "*' AND"
End If
If Not IsNull(Me.cboF1F2) Then
strWhere = strWhere & " (tbljob_info.[F1/F2]) Like '*" & Me.cboF1F2 & "*'
AND"
End If
If Not IsNull(Me.txtEWO) Then
strWhere = strWhere & " (tbljob_info.EWO) Like '*" & Me.txtEWO & "*' AND"
End If
'Remove the last AND from the SQL statment
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)
'Pass the SQL to the RowSource of the listbox
Me.lstJobInfo.RowSource = strSQL & " " & strWhere & "" & strOrder
End Sub.
I copied the code from an Access tips website, and just changed the names.
It works great in acting as a filter to populate the list box, but the code
for the double click event of the list box does not work. Does anyone know
how to make this work for me? Thanks in advance.