Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

an easy one

Question posted by: Jim (Guest) on July 4th, 2008 03:35 AM
anyone know how to run an append (well any query I suppose) from code.

I'm rusty and actually have never ran a query from code.

I'm thinking docmd.runquery("query")

TIA


Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Tom van Stiphout's Avatar
Tom van Stiphout
Guest
n/a Posts
July 4th, 2008
03:35 AM
#2

Re: an easy one
On Fri, 04 Jul 2008 03:26:48 GMT, "Jim" <jimt@pioneers.cawrote:

Not "any query", but "any action query":
DoCmd.RunSQL

The help file would have told you runquery is not a legal action.
Don't use the newsgroups in lieu of the help file.

-Tom.

Quote:
Originally Posted by
>anyone know how to run an append (well any query I suppose) from code.
>
>I'm rusty and actually have never ran a query from code.
>
>I'm thinking docmd.runquery("query")
>
>TIA
>


Jim's Avatar
Jim
Guest
n/a Posts
July 4th, 2008
03:45 AM
#3

Re: an easy one
Hey dude hold your fire.

I'm not a code genius. I've been trying to find it myself in help and on the
access web. I don't want to run SQL per se, I already have an append query
created and just want to run it - simplifying things for myself, so I don't
get caught up in code.

Is this not an access (all access, not just code and SQL) newsgroup?




"Tom van Stiphout" <no.spam.tom7744@cox.netwrote in message
news:m86r64l54gfujv5s5o4u47kle40tcse77i@4ax.com...
Quote:
Originally Posted by
On Fri, 04 Jul 2008 03:26:48 GMT, "Jim" <jimt@pioneers.cawrote:
>
Not "any query", but "any action query":
DoCmd.RunSQL
>
The help file would have told you runquery is not a legal action.
Don't use the newsgroups in lieu of the help file.
>
-Tom.
>
>
Quote:
Originally Posted by
>>anyone know how to run an append (well any query I suppose) from code.
>>
>>I'm rusty and actually have never ran a query from code.
>>
>>I'm thinking docmd.runquery("query")
>>
>>TIA
>>




Rick Brandt's Avatar
Rick Brandt
Guest
n/a Posts
July 4th, 2008
12:35 PM
#4

Re: an easy one
Jim wrote:
Quote:
Originally Posted by
I'll give it a try in the name of curiousity to get the sql stuff to
work. I did finally find out a way to run a query from code with the
command button wizard. It couldn't be simpler. When I invoked the
command button wizard, under miscellaneous operations, there was a
"run a query" option.
But, I should persist in trying to make this run SQL work to, as I
may need to use variables some day and runSQL looks for efficient in
that sense.
Thanks all.


CurrentDB.Execute "QueryName", dbFailOnError

That is actually better than RunSQL in most cases since it can also use a
SQL statement in place of the query name. Better error handling and no
confirmation prompts.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com



fredg's Avatar
fredg
Guest
n/a Posts
July 4th, 2008
01:25 PM
#5

Re: an easy one
On Fri, 04 Jul 2008 03:41:36 GMT, Jim wrote:
Quote:
Originally Posted by
Hey dude hold your fire.
>
I'm not a code genius. I've been trying to find it myself in help and on the
access web. I don't want to run SQL per se, I already have an append query
created and just want to run it - simplifying things for myself, so I don't
get caught up in code.
>
Is this not an access (all access, not just code and SQL) newsgroup?
>
"Tom van Stiphout" <no.spam.tom7744@cox.netwrote in message
news:m86r64l54gfujv5s5o4u47kle40tcse77i@4ax.com...
Quote:
Originally Posted by
>On Fri, 04 Jul 2008 03:26:48 GMT, "Jim" <jimt@pioneers.cawrote:
>>
>Not "any query", but "any action query":
>DoCmd.RunSQL
>>
>The help file would have told you runquery is not a legal action.
>Don't use the newsgroups in lieu of the help file.
>>
>-Tom.
>>
>>
Quote:
Originally Posted by
>>>anyone know how to run an append (well any query I suppose) from code.
>>>
>>>I'm rusty and actually have never ran a query from code.
>>>
>>>I'm thinking docmd.runquery("query")
>>>
>>>TIA
>>>


The help files in Access are split into different sections.
There is an Access help and a VBA help.
Since you are dealing with code you need to look in the Code (VBA help
) section.
Open any code window (or click Ctrl+G) and then click on help.
Or you can use the Command Button wizard to add a command button to a
form. One of the choices is to run a Query. Let it create the code,
then examine what the wizard wrote.

You can use the
DoCmd.OpenQuery "QueryName"
method...
Or
CurrentDb.Execute "QueryName"

Look them up in VBA help.
While there, also look up SetWarnings as well.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

KC-Mass's Avatar
KC-Mass
Guest
n/a Posts
July 6th, 2008
02:55 PM
#6

Re: an easy one
Hi Rick

What error info will that yeild and how would it best be handled?

Thx

Kevin


"Rick Brandt" <rickbrandt2@hotmail.comwrote in message
news:uIobk.543$cn7.326@flpi145.ffdc.sbc.com...
Quote:
Originally Posted by
Jim wrote:
Quote:
Originally Posted by
>I'll give it a try in the name of curiousity to get the sql stuff to
>work. I did finally find out a way to run a query from code with the
>command button wizard. It couldn't be simpler. When I invoked the
>command button wizard, under miscellaneous operations, there was a
>"run a query" option.
>But, I should persist in trying to make this run SQL work to, as I
>may need to use variables some day and runSQL looks for efficient in
>that sense.
>Thanks all.

>
CurrentDB.Execute "QueryName", dbFailOnError
>
That is actually better than RunSQL in most cases since it can also use a
SQL statement in place of the query name. Better error handling and no
confirmation prompts.
>
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
>




Rick Brandt's Avatar
Rick Brandt
Guest
n/a Posts
July 7th, 2008
09:55 PM
#7

Re: an easy one
KC-Mass wrote:
Quote:
Originally Posted by
Hi Rick
>
What error info will that yeild and how would it best be handled?


The typical problems that can occur when running an action query will prompt
the user with RunSQL, but they are not treated as errors "to your code". If
your code needs to know whether everything went well with the query then the
Execute method is the way to go. These include (but are not limited to)...

Inserting/Updating a row that violates a unique index (duplicate)
Inserting/Updating a row missing a required field value
Inserting a child row without a matching parent row in a related table (RI
enabled)
Deleting a parent row when there are still dependent children rows (RI
enabled but not cascade delete)


--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com



KC-Mass's Avatar
KC-Mass
Guest
n/a Posts
July 8th, 2008
02:35 PM
#8

Re: an easy one
Thanks much - good info.

"Rick Brandt" <rickbrandt2@hotmail.comwrote in message
news:Kbwck.3003$cn7.2516@flpi145.ffdc.sbc.com...
Quote:
Originally Posted by
KC-Mass wrote:
Quote:
Originally Posted by
>Hi Rick
>>
>What error info will that yeild and how would it best be handled?

>
The typical problems that can occur when running an action query will
prompt the user with RunSQL, but they are not treated as errors "to your
code". If your code needs to know whether everything went well with the
query then the Execute method is the way to go. These include (but are
not limited to)...
>
Inserting/Updating a row that violates a unique index (duplicate)
Inserting/Updating a row missing a required field value
Inserting a child row without a matching parent row in a related table (RI
enabled)
Deleting a parent row when there are still dependent children rows (RI
enabled but not cascade delete)
>
>
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
>




 
Not the answer you were looking for? Post your question . . .
183,962 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors