Use a SQL statement to open form
I'm trying to write a small SQL query that will allow me to open a form only with that person records. This is in Access 2003. The error I'm getting is a syntax error in the query
VB Code:
' Dim variables used
Dim stDocName As String
Dim stLinkCriteria As String
' Form name is 1486
stDocName = "1486"
' Find out who is selected in the Employee combo box and make SUPER (text box on 1486) equal to that person (so it will filter records by the person)
stLinkCriteria = "[SUPER]=" & "'" & Me.cboEmployee & "'"
' Create query that selects only the records of that person
sSQL = "SELECT * FROM 1486 WHERE stLinkCriteria"
' Open the form
DoCmd.OpenForm stDocName, , , sSQL
Re: Use a SQL statement to open form
I'm presuming that 1486 is the name of the form.. you cannot perform SQL against a form.. if 1486 is the table then what does the value in cboEmployee return.. is this a string value or numeric?
Re: Use a SQL statement to open form
Quote:
Originally Posted by dannymking
I'm presuming that 1486 is the name of the form.. you cannot perform SQL against a form.. if 1486 is the table then what does the value in cboEmployee return.. is this a string value or numeric?
It returns a string (John Doe), then I want the form to open with only the records that have the SUPER (feild name) of John Doe..
Re: Use a SQL statement to open form
Try putting the value of the variable into the string, rather than the variable name ;)
VB Code:
sSQL = "SELECT * FROM 1486 WHERE " & stLinkCriteria
Re: Use a SQL statement to open form
Your error is here..
Code:
' Open the form
DoCmd.OpenForm stDocName, , , sSQL
You are trying to open the form using the full SQL as the open argument.. Try just sending "[Super]=" & stLinkCriteria
Or open the form in design view set the recordsource to the SQL, save and close it and then open the form normally