Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / November 2006

Tip: Looking for answers? Try searching our database.

Append Query in VBA - to append VBA variable values to Access tabl

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Agent Dagnamit - 01 Nov 2006 11:39 GMT
I want to run an append query to append data to an existing Access table
calculated from procedures run against a recordset.  This doesnt work:

DoCmd.RunSQL "INSERT INTO Results ( [AXA Ref] ) SELECT [Axaref] AS [AXA Ref]"

..even though "AXA Ref" is definately a valid field in table "Results", and
"Axaref" is an existing VBA variable (with value 1).  When I run this,, the
Access "Enter Parameter Value" dialogue box appears.

However, I can assign the value "Axaref" to a field on a form, and then use
that form control's value in an append query, like this:

Forms![AdvertForm].[axa] = AxaRef

DoCmd.RunSQL "INSERT INTO Results ( [AXA Ref] ) SELECT
Forms![AdvertForm].[axa] AS [AXA Ref]

I'm sure it isnt really necessary to transfer the value of a VBA variable to
a Form control before it is useable in an Access Database....is it?!
Alex Dybenko - 01 Nov 2006 12:38 GMT
Hi,
try:
DoCmd.RunSQL "INSERT INTO Results ( [AXA Ref] ) Values(" & AxaRef & ")"

if AxaRef is a string variable - then make sure to include it in quotes

Signature

Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

>I want to run an append query to append data to an existing Access table
> calculated from procedures run against a recordset.  This doesnt work:
[quoted text clipped - 20 lines]
> to
> a Form control before it is useable in an Access Database....is it?!
Agent Dagnamit - 01 Nov 2006 13:02 GMT
Thanks Alex, that works.  What is the reasoning behind the "&" character,
presumably refering to my VBA variable?

Also, sorry to bug you again, what would the code be if AxaRef was a date
field that I wanted to append?

> Hi,
> try:
[quoted text clipped - 26 lines]
> > to
> > a Form control before it is useable in an Access Database....is it?!
Alex Dybenko - 01 Nov 2006 15:07 GMT
Hi,

& AxaRef - will add a value of AxaRef, converted into string, to SQL string.
as for dates - you have to put them in #mm/dd/yyyy# format, so your code
will be the following:

DoCmd.RunSQL "INSERT INTO Results ( [AXA Ref] ) Values(#" &
format(AxaRef,"mm\/dd\/yyyy") & "#)"

Signature

Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

> Thanks Alex, that works.  What is the reasoning behind the "&" character,
> presumably refering to my VBA variable?
[quoted text clipped - 33 lines]
>> > to
>> > a Form control before it is useable in an Access Database....is it?!
Agent Dagnamit - 01 Nov 2006 17:25 GMT
Thanks Alex, that's been a great help

Stuart

> Hi,
>
[quoted text clipped - 42 lines]
> >> > to
> >> > a Form control before it is useable in an Access Database....is it?!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.