Good day all,
I have a database with several tables, forms, reports, and queries. I would like to create a form that include a textbox and a command button. What I want to query is all people with the Last Name of (whatever value is in the text box) from the table 'Spotters'. I have included a sample of my database. Thanks in advance I have tried to implement code that I got from another example but have failed to get it to work properly. Specifically the form in question is frmReports in the included example. I want to generate a report using a query built with input from the text box included on the frmReports form. Any help is greatly appreciated. The code I attached to the Generate Report button on this form follows. I was unable to implement this properly. Although this code looks promising.
I hope I have explained this well enough. If not please ask and I will attempt to explain more thoroughly.
I have a database with several tables, forms, reports, and queries. I would like to create a form that include a textbox and a command button. What I want to query is all people with the Last Name of (whatever value is in the text box) from the table 'Spotters'. I have included a sample of my database. Thanks in advance I have tried to implement code that I got from another example but have failed to get it to work properly. Specifically the form in question is frmReports in the included example. I want to generate a report using a query built with input from the text box included on the frmReports form. Any help is greatly appreciated. The code I attached to the Generate Report button on this form follows. I was unable to implement this properly. Although this code looks promising.
Code:
Private Sub cmdLastNameSearch_Click()
On Error Resume Next
Dim ctl As Control
Dim sSQL As String
Dim sWhereClause As String
'Initialize the Where Clause variable.
wWhereClause = "Where"
'Start the first part of the select statement.
sSQL = "Select * from spotters "
'Loop through each control on the form to get its value.
For Each ctl In Me.Controls
With ctl
'the only control you are using is the text box.
'However, you can add as many types of controls as you want.
Select Case .ControlType
Case acTextBox
.SetFocus
'This is the function that actually buids
'the clause.
If sWhereClause = "Where " Then
sWhereClause = sWhereClause & BuildCriteria(.Name, dbText, .Text)
Else
sWhereClause = sWhereClause & " and " & BuildCriteria(.Name, dbText, .Text)
End If
End Select
End With
Next ctl
'set the forms recordsource equal to the new
'select statement.
Me.txtLastName = sSQL & sWhereClause
Me.RecordSource = sSQL & sWhereClause
Me.Requery
End Sub