Getting an syntex error:-

sbaud2003

Member
Local time
Tomorrow, 04:20
Joined
Apr 5, 2020
Messages
186
Private Sub CMDSEARCH_Click()

Dim SQL As String
SQL = "SELECT MASTER.[AC_NO], MASTER.[EMP_NAME], MASTER.[DOR], MASTER.[PPO_NO]" _
& "FORM MASTER" _
& "WHERE [EMP_NAME] LIKE '*" & Me.TXTKEY & "*' " _
& "ORDER BY MASTER.[EMP_NAME]"

Me.SUB_FORM_LIST.Form.RecordSource = SQL
Me.SUB_FORM_LIST.Form.Requery
End Sub
 
Debug.Print sql
ALWAYS test your sql string
 
100% what Gasman said. You are looking through a prism of VBA to see if the SQL inside is valid. Get down to the issue and find out what your SQL actually is. If it passes the initial smell test and looks fine (hint, your's won't if you pay attention) you then paste that SQL into an Access Query object and try and run it to see if it produces results you expect. If it does you should be good, if not the Access Query object will help you find the issue.
 
Now an observation. When you concatenate strings, be sure to include spaces that would be between other elements. AND watch for the spelling of your keywords. I have noticed both types of error in what you posted.
 
Two obvious errors - you need either trailing spaces or leading spaces when you concatenate the strings. And you are missing a " From "

PS, A field named txtKey sounds like it might be numeric. Are you sure it is a string? LIKE is used ONLY with strings and ONLY if they are partial. If you have a complete value, ALWAYS use the = operator. LIKE prevents the database engine from utilizing indexes. So to perform the search, it must examine the data RBAR. Row by agonizing row. The larger the table, the longer this will take. So, although we do sometimes need to use LIKE, we never use it when we don't need to.
 

Users who are viewing this thread

Back
Top Bottom