Hi have have made a userinput query but it does not work. My plan is t have a query section and users can input data to query like Customers and related sales, etc. Here is my code:
Private Sub Command0_Click()
Sub MyFirstConnection()
Dim con1 As ADODB.Connection
Dim recSet1 As ADODB.Recordset
Dim strSQL As String
Dim strSearch As String
strSearch = InputBox("Enter Shipper Name", "Search Criterion")
strSQL = "SELECT ShipperName, Phone, Fax, Email, Contact FROM Shipper" & _
" WHERE ShipperName = " & " '" & strSearch & "'"
Set con1 = CurrentProject.Connection
Set recSet1 = New ADODB.Recordset
recSet1.Open strSQL, con1
Do Until recSet1.EOF
Debug.Print recSet1.Fields("txtCustFirstName"), _
recSet1.Fields("txtCustLastName")
recSet1.MoveNext
Loop
recSet1.Close
con1.Close
Set con1 = Nothing
Set recSet1 = NothingEnd Sub
DoCmd.RunSQL strSQL
End Sub
I put this code under the click event because when the user clicks on it I want the input box to pop up and they insert what record they want to query. was this the right place to put it?
Private Sub Command0_Click()
Sub MyFirstConnection()
Dim con1 As ADODB.Connection
Dim recSet1 As ADODB.Recordset
Dim strSQL As String
Dim strSearch As String
strSearch = InputBox("Enter Shipper Name", "Search Criterion")
strSQL = "SELECT ShipperName, Phone, Fax, Email, Contact FROM Shipper" & _
" WHERE ShipperName = " & " '" & strSearch & "'"
Set con1 = CurrentProject.Connection
Set recSet1 = New ADODB.Recordset
recSet1.Open strSQL, con1
Do Until recSet1.EOF
Debug.Print recSet1.Fields("txtCustFirstName"), _
recSet1.Fields("txtCustLastName")
recSet1.MoveNext
Loop
recSet1.Close
con1.Close
Set con1 = Nothing
Set recSet1 = NothingEnd Sub
DoCmd.RunSQL strSQL
End Sub
I put this code under the click event because when the user clicks on it I want the input box to pop up and they insert what record they want to query. was this the right place to put it?