Runsql action requires an argument consisting sql statement

aman

Registered User.
Local time
Today, 11:43
Joined
Oct 16, 2008
Messages
1,251
Hi guys

I am trying to display the result of select query on the screen .I have written the following code but its giving me an error "Runsql action requires an argument consisting sql statement"

Code:
Dim i As String
Dim strSQL As String
'Dim qdf As QueryDef
i = DLookup("Option", "maintable", "uniq='" & Text0 & "'")
If i = "Work From AXADept" Then
strSQL = "select RDateMPU,Received_by,SendingDept,RefNo,Productname,RDateDept,Corresdate,Reason,Datesent,sendername,RecMPU,collectedby,Contactno,Datecollected,Time from maintable;"
DoCmd.RunSQL ssql
End If

May be DOcmd.runql statement is not used with select statement but it can be used for insert,alter,delete statements. Can anyone please help me how can i display the select statment result on the screen.

Thanks
AMan
 
If I write:
DoCmd.OpenQuery ("strSQL") instead of docmd.runsql strSQL then it gives me the following error:

"Microsoft Access can't find the object strSQL"

Any help would be much appreciated.

Thanks
Aman
 
Remove the quotes from around the variable name

David
 
Hi David

If I remove the quotes from around the variable then it gives me an error:

Microsoft Access can't find the object 'select statement....

I hope you can help me in this.

Regards
Aman
 
Baoblarson I am using docmd.openquery and not docmd.runsql.. please see the above posts.

Thanks
 
I want to display the result on the screen thats why i am using docmd.openquery option. When the user types the reference id in the textbox then the details of that ref id should be displayed on the screen when the user press command button.

I hope you understand my problem.

Thanks
 
I have created a form and I am writing this code in the command button click event of that form.

Code:
Dim i As String
Dim strSQL As String
i = DLookup("Option", "maintable", "uniq='" & Text0 & "'")
If i = "Work From AXADept" Then
strSQL = "select RDateMPU,Received_by,SendingDept,RefNo,Productname,RDateDept,Corresdate,Reason,Datesent,sendername,RecMPU,collectedby,Contactno,Datecollected,Time from maintable;"
DoCmd.openquery strSQL
End If

Cheers
 
Hi Boblarson

I don't want to use listbox. I want to show the query result on the screen.

Thanks
Aman
 
Add a WHERE string - I know you don't need one but without it won't be recognized as a SQL
 
Hi again @formula2

I've just spotted that you are a new forum member so a warm welcome to AWF.

However, your comment in this ancient thread is incorrect

You can write SQL like this:
Code:
SELECT * FROM Table1

No WHERE is required for this to select all records from a table
However as pointed out in an earlier post, you CANNOT do this

Code:
DoCmd.RunSQL "SELECT * FROM Table1"

as you can only run action queries (append/update/delete)
 
Yes sorry - it was a while ago and I knew I added something into the sql string. Thinking about it I made a table
so
sqlstr="select xyd into tempTable from tblname"
docmd.runsql sqlstr
docmd.OpenTable "TempTable"
 
No problem

Suggest you do an introductory post as is recommended for new members
 

Users who are viewing this thread

Back
Top Bottom