|
-
Feb 4th, 2006, 08:13 AM
#1
Thread Starter
Hyperactive Member
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
-
Feb 4th, 2006, 08:43 AM
#2
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?
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Feb 4th, 2006, 08:53 AM
#3
Thread Starter
Hyperactive Member
Re: Use a SQL statement to open form
 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..
-
Feb 4th, 2006, 09:30 AM
#4
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
-
Feb 4th, 2006, 09:34 AM
#5
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
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|