Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone tells me

Status
Not open for further replies.
Sep 21, 2001
28
US
I have been trying to figure this out for hours. Can someone help. I have this SQL statment in Access, and it keeps giving me this error message:

Run-time error '2342':

A RunSQL action requires an argument consisting of an SQL statement.

Private Sub Command2_Click()

If cmbBargainUnit.Value = "A" Then
DoCmd.RunSQL "Select PermanentTable.* from PermanentTable;", -1
DoCmd.OpenReport "rptBargainingUnit-A", acViewPreview
End If

End Sub


This statement looks simple enough, but it's not able to execuute.

 

RunSQL can only be used to carry out Action Queries such as Update, Insert, Delete, Create Table, Drop Table, etc. It cannot be used to return a record set or Select records. If you just want to open a query, create and save it. Then use the OpenQuery Method of DoCmd to open it. Or use the OpenTable Method.

DoCmd.OpenTable "PermanentTable" Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Thanks. That would explain why I keep getting that run-time error message. What I was planning to do was to be able to execute a query with certain criteria attach to it. For example, there is a combo box with numbers A-Z, if someone select A, it will change the Letter field in the query and retrieve records w/letter A in that field. It would be easier to create 26 queries for each letter, but I wonder if there's an alternative of doing this. If anyone has the answer, don't hesitate to share the knowledge.

Query: ID, FNAME, LNAME, CONTACT, LETTER
 

You can reference an object on a table from a query. There are numerous examples posted around these forums.

Example: Basic syntax

Select * From table
Where Letter = [forms].[form_name].[combo_name] Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top