Connecting Tech Pros Worldwide Help | Site Map

an easy one

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 4th, 2008, 03:35 AM
Jim
Guest
 
Posts: n/a
Default an easy one

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



  #2  
Old July 4th, 2008, 03:35 AM
Tom van Stiphout
Guest
 
Posts: n/a
Default 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:
>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
>
  #3  
Old July 4th, 2008, 03:45 AM
Jim
Guest
 
Posts: n/a
Default 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:
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:
>>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
>>

  #4  
Old July 4th, 2008, 12:35 PM
Rick Brandt
Guest
 
Posts: n/a
Default Re: an easy one (it was easy)

Jim wrote:
Quote:
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


  #5  
Old July 4th, 2008, 01:25 PM
fredg
Guest
 
Posts: n/a
Default Re: an easy one

On Fri, 04 Jul 2008 03:41:36 GMT, Jim wrote:
Quote:
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:
>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:
>>>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
  #6  
Old July 6th, 2008, 02:55 PM
KC-Mass
Guest
 
Posts: n/a
Default Re: an easy one (it was easy)

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:
Jim wrote:
Quote:
>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
>

  #7  
Old July 7th, 2008, 09:55 PM
Rick Brandt
Guest
 
Posts: n/a
Default Re: an easy one (it was easy)

KC-Mass wrote:
Quote:
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


  #8  
Old July 8th, 2008, 02:35 PM
KC-Mass
Guest
 
Posts: n/a
Default Re: an easy one (it was easy)

Thanks much - good info.

"Rick Brandt" <rickbrandt2@hotmail.comwrote in message
news:Kbwck.3003$cn7.2516@flpi145.ffdc.sbc.com...
Quote:
KC-Mass wrote:
Quote:
>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
>

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.