drop down box and search

siamsunset

New Member
Joined
Jan 25, 2005
Messages
29
Hi everyone,
I have set up a search form that searches information in a table related to whatever is typed into a text box, it returns the matches in a list box and i can then double click the result and open it in another form. We are a printing firm and i use this to search for jobs by name, number or type of printing job. It works fine with words in text boxes but what i would love to do is to be able to do is show jobs that are completed or not completed using a drop down box with yes/no values. If no value is selected it shows all jobs completed or not. If yes is selected is shows just completed jobs ect.....I am a total access noob so im not sure how to go about this the right way. Here is a list of the code i have for the text box search.

Code:
Option Compare Database

Private Sub cmdSearch_Click()
'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 jobsinfo.JobNumber, Jobsinfo.JobNumber, jobsInfo.FirstName, jobsinfo.LastName, jobsinfo.company,  jobsinfo.jobtype " & _
"FROM jobsinfo"

strWhere = "WHERE"

strOrder = "ORDER BY jobsinfo.JobNumber;"


'Set the WHERE clause for the Listbox RowSource if information has been entered into a field on the form
If Not IsNull(Me.txtFName) Then '<--If the textbox txtFName contains no data THEN do nothing
strWhere = strWhere & " (Jobsinfo.JobNumber) Like '*" & Me.txtFName & "*'  AND" '<--otherwise, apply the LIKE statment to the QueryDef
End If

If Not IsNull(Me.txtLName) Then
strWhere = strWhere & " (jobsinfo.LastName) Like '*" & Me.txtLName & "*'  AND"
End If

If Not IsNull(Me.txtCity) Then
strWhere = strWhere & " (jobsinfo.Company) Like '*" & Me.txtCity & "*'  AND"
End If

If Not IsNull(Me.txtState) Then
strWhere = strWhere & " (jobsinfo.jobtype) Like '*" & Me.txtState & "*'  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.lstCustInfo.RowSource = strSQL & " " & strWhere & "" & strOrder

End Sub



Private Sub lstCustInfo_DblClick(Cancel As Integer)
'Open tblinfo based on the ID from lstCustInfo listbox

DoCmd.OpenForm "jobsform", , , "[Jobnumber] = " & Me.lstCustInfo, , acDialog

End Sub

Private Sub txtCity_BeforeUpdate(Cancel As Integer)

End Sub




Thanks alot in advance
Ben
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Ben

How are you determining whether a job has been completed?
 
Upvote 0

Forum statistics

Threads
1,221,889
Messages
6,162,624
Members
451,778
Latest member
ragananthony7911

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top