?
Solved

On Click Event Procedure in Access

Posted on 2014-03-15
14
Medium Priority
?
1,913 Views
Last Modified: 2014-03-15
Any clue what is causing Access to display this error when attempting to run this event procedure?

Receiving Run-time error '2342':
A RunSQL action requires an argument consisting of an SQL statement.

Here is the statement in the On Click [Event Procedure]:
DoCmd.RunSQL "SELECT FileTree.Location FROM FileTree LEFT JOIN tblBilder ON FileTree.[Location] = tblBilder.[location] WHERE (((tblBilder.location) Is Null))"
0
Comment
Question by:clock1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
14 Comments
 
LVL 58
ID: 39931565
Try,

DoCmd.RunSQL "SELECT FileTree.Location FROM FileTree LEFT JOIN tblBilder ON FileTree.[Location] = tblBilder.[location] WHERE tblBilder.location Is Null;"

 and see if that flies.   If not, open the query designer, switch to SQL view, paste in the statement, then try switching to design view, and if it does, execute it.

 I don't see anything really right off, but there must be something in there.

Jim.
0
 

Author Comment

by:clock1
ID: 39931570
I pasted the statement which included (;) at the end of the statement and still seeing same error.
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39931572
Too many beers yesterday Jim??

It's because your SQL is a simple select which returns records - not meaningful here.
You need an action query - update, append, or delete - or a statement that opens the selection: DoCmd.OpenQuery ... or the like.

/gustav
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

Author Comment

by:clock1
ID: 39931582
/gustav:

I used this statement to open the query that contains the SQL:
DoCmd.OpenQuery ("FileTree Without Matching tblBilder")

However this actually opens the query and displays the results on the screen. My objective is that the On Click [Event Procedure] runs the query and my menu (where button is located) continues to display.  Making any sense?
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39931587
No that doesn't make sense.
Why should you run the query if you neither wish to watch the result or use the records?

Note the difference between a select and an action query.

/gustav
0
 

Author Comment

by:clock1
ID: 39931590
/gustav:

Once the select query runs and the records are selected, I run an append query to add the selected records to a table.
0
 

Author Comment

by:clock1
ID: 39931594
/gustav:

To be clear, there are 2 queries because I'm appending to a table that is used in the select query. Would be fantastic If there's a way to do that in one-shot.
0
 

Author Comment

by:clock1
ID: 39931596
/gustav:

Here's the SQL to append:

DoCmd.RunSQL "INSERT INTO tblBilder ( Location )SELECT [FileTree Without Matching tblBilder].Location FROM [FileTree Without Matching tblBilder];"
0
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 1500 total points
ID: 39931602
That's easy. Create and test that append query and call it with CurrentDb.Execute:

http://msdn.microsoft.com/en-us/library/office/ff821728(v=office.15).aspx

/gustav
0
 

Author Comment

by:clock1
ID: 39931613
/gustav:

When using DoCmd.OpenQuery

Can one prevent Access from displaying the query results?
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39931624
No. That's the purpose of this command.
So if you don't want to display records, you don't use that command.

As said, if you want to append records, run (call) an append query. It's that simple.

/gustav
0
 
LVL 58
ID: 39931646
<<Too many beers yesterday Jim??>>

  I was so focused on the statement, I didn't even think about what was being done.

Jim.
0
 

Author Comment

by:clock1
ID: 39931742
/gustav:

Took a few trys, and works like a charm. Thanks!
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39931916
You are welcome!

/gustav
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question