search on form controlled by a textbox

wchitamb

New member
Local time
Today, 20:01
Joined
May 24, 2016
Messages
6
I have a textbox & a button on a form and would like to search a table. and have the result either on a subform or excel. with the code below nothing is happening.

Private Sub Command114_Click()
Dim strSQL As String
Dim strMyString As String
Dim rs As DAO.Recordset

strMyString = Forms![Main_Menu]!StrArticle
strSQL = "SELECT * FROM tblArticles " & _
"WHERE ArticleNo = '" & strMyString & "';"

Debug.Print strSQL

Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)

If Not (rs.EOF) Then
'Debug.Print rs![strMyString]
Else
Debug.Print "Nothing found"
End If

Set rs = Nothing
End Sub
 
Have you looked at the Immediate window after running the code? I'd probably do:

Me.SubformName.Form.RecordSource = strSQL
 
Thanks.i ended up having a text-box and a button (behind the button was a query that read the parameter on the text-box) and run the query to display the results
 
Most of us prevent users from seeing tables and queries, only forms and reports. You have little control over format and interactivity in tables and queries, and no events to work with.
 

Users who are viewing this thread

Back
Top Bottom