SQL Query in VBA

G

Guest

I'm trying to run a query in VBA. Code as follows:

SQL = "SELECT Temp.Polisnommer " & _
"FROM (Temp LEFT JOIN LMS ON " & _
"Temp.Polisnommer = LMS.Polisnommer) " & _
"WHERE (((LMS.Polisnommer) Is Null));"


DoCmd.RunSQL SQL

When I step through, I get the following error message:


Error Message 2342

'A runSQL action requires an argument consisting of an SQL statement. '

The above SQL was tested in the Query SQL area and does work. But as soon as
I try to run it in the VBA shell, it doesn't. WHY?

Thanks
 
Y

Yvonne Anderson

What it is this group, and why is it appearing on my computer?

Yvonne Michele Anderson
(e-mail address removed)
 
D

Douglas J. Steele

As the message says, DoCmd.RunSQL only works with Action queries (INSERT
INTO, UPDATE, DELETE).

What are you hoping to have happen? You could save the SQL as a query and
then use DoCmd.OpenQuery "NameOfQuery", but to be honest, that doesn't
strike me as a particularly friendly user interface.
 
G

Guest

Hey

I have linked tables called Temp and LMS. The user imports data via a
button. If their is data missing in the primary table LMS that is in Temp, I
want to run the query to test. This concludes then with a subform that shows
the user which data is not in the primary detail and needs to be added. What
this query does in fact is to do a left join, and showing all data in Test
that is Null in LMS.

Does this make sense?
 
D

Douglas J. Steele

My point was showing the results of a query as a query (as opposed to as a
form, where you can control what's done with the data) isn't a very friendly
interface.

If that's what you really want, I told you how you can do it. My advice,
though, is to create a form and use that query as its recordsource.
 
G

Guest

How do I not let the query show. The help function have different views that
you can see the data. I don't want my user to see the query.
 
G

Guest

Thank you. I've sorted it out by running a requery and making the subform not
visible until when I want the user to see the data.

Once again, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Using Date fields in SQL 2
Stop Query 4
SQL statement doesn't work in VBA. 2
SQL -- VBA 3
VBA -- SQL 9
Running a SELECT statement 2
Open select query in vba code 4
SQL - VBA once again 10

Top