User-Input queries?

ITHELP85

Registered User.
Local time
Yesterday, 22:53
Joined
Nov 18, 2008
Messages
10
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?
 
recSet1.Close
con1.Close
Set con1 = Nothing
Set recSet1 = NothingEnd Sub
DoCmd.RunSQL strSQL
End Sub

The end of the code is quite messy, as is. And what is "DoCmd.RunSQL strSQL" supposed to do there? Maybe this version would work better:

recSet1.Close
con1.Close
Set con1 = Nothing
Set recSet1 = Nothing
End Sub

Also, I'm not sure about your quotes in:

" WHERE ShipperName = " & " '" & strSearch & "'"

The following might yield better results:

" WHERE ShipperName = '" & strSearch & "'"


HTH
 

Users who are viewing this thread

Back
Top Bottom