Solved Syntax error in query expression (1 Viewer)

rondon

Member
Local time
Today, 23:10
Joined
May 16, 2020
Messages
53
I have 2 tables

tbl_Reports_Tabled (key =Report_ID) and tbl_Recommendations (key REC_ID) they are link 1-many by Report_ID, based on the tables I created a Subform with frm_Reports_Table as the parent and frm_Recommendation as the embedded form.

I have built a search form frmSearchREC based on a query which included Report_ID. The search form has a list box that displays all of the recommendation including the Report_ID. A txtbox called txtSearch allows the user to enter free text returning results in the list box (this works well). Once the record is returned in the list box I want the user to click on it and open the frm_Reports_Tabled filtering to the Report_ID in the listbox . I have the following code



Private Sub SearchResults_Click()

On Error GoTo Err_Command24_Click

Dim stDocName As String

Dim stLinkCriteria As String

stDocName = "frm_Reports_tabled"

stLinkCriteria = "[Report_ID]=" & Me![SearchResults]

DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.Close acForm, "frmSearchREC", acSaveYes

Exit_Command24_Click:

Exit Sub

Err_Command24_Click:

MsgBox Err.Description

Resume Exit_Command24_Click

End Sub

The code line stLinkCriteria = "[Report_ID]=" & Me![SearchResults] appears to be wrong

When I click on any line in the ListBox example - Report_ID of 2000_83 it returns the following error Syntax error in query expression ‘[Report_ID] = 2000_83

Any help would be greatly received as I have been trying to resolve this for days. Thanks Ron
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:10
Joined
May 7, 2009
Messages
19,245
does the First column of the listbox include the Report_ID/Rec_ID (which is available)?

the one you post is String:

stLinkCriteria = "[Report_ID]='" & Replace(Me![SearchResults], "'", "''") & "'"
 

rondon

Member
Local time
Today, 23:10
Joined
May 16, 2020
Messages
53
does the First column of the listbox include the Report_ID/Rec_ID (which is available)?

the one you post is String:

stLinkCriteria = "[Report_ID]='" & Replace(Me![SearchResults], "'", "''") & "'"


Thank you very much for this it worked very well, I really appreciate you time and assistance
Regards Ron
 

Users who are viewing this thread

Top Bottom