Hi,
I'm trying to display my query results onto an Access subform. I have written a very simple SQL statement to preform a query depending on a user's choice of a drop down box in an attempt to display the resultset on the subform.
Example:
If the user selects 10 from the combobox, then it does a query saying "SELECT * from tblD10;"
No matter what the SQL statement is, (i've tried simple ones such as this and more complex queries that I've written before and are known-working) I get the VBA error:
'Run-time error 2342
A RunSQL action requires an argument consisting of an SQL statement.'
I tried using both annotations of the 'all' object as you can see in the code I have: "SELECT *" and "SELECT tblD10.*"
Below is the short snippet of code that gives the error in VB. I'm not sure if having the 'DoCmd.RunSQL' in an 'if statment' matters or not... I wouldn't imagine so.
I'm using Office 2003 w/ SP2 on XP machine...
Any insight much appreciated.
Thanks in advance.
I'm trying to display my query results onto an Access subform. I have written a very simple SQL statement to preform a query depending on a user's choice of a drop down box in an attempt to display the resultset on the subform.
Example:
If the user selects 10 from the combobox, then it does a query saying "SELECT * from tblD10;"
No matter what the SQL statement is, (i've tried simple ones such as this and more complex queries that I've written before and are known-working) I get the VBA error:
'Run-time error 2342
A RunSQL action requires an argument consisting of an SQL statement.'
I tried using both annotations of the 'all' object as you can see in the code I have: "SELECT *" and "SELECT tblD10.*"
Below is the short snippet of code that gives the error in VB. I'm not sure if having the 'DoCmd.RunSQL' in an 'if statment' matters or not... I wouldn't imagine so.
I'm using Office 2003 w/ SP2 on XP machine...
Any insight much appreciated.
Thanks in advance.
Code:
Private Sub cboSearchDept_AfterUpdate() Dim rs As Recordset Dim db As Database Dim frm2 As SubForm Set frm2 = Forms!frmSearch!subSearch Dim strSQL10 As String Dim strSQL11 As String Set db = CurrentDb [B] strSQL10 = "SELECT * FROM tblD10;" strSQL11 = "SELECT tblD11.* FROM tblD11;" [/B] If cboSearchDept = 10 Then DoCmd.RunSQL strSQL10 End If If cboSearchDept = 11 Then DoCmd.RunSQL strSQL11 End If Set rs = frm2 Forms!frmSearch!subSearch.Requery End Sub
Comment