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 / January 2006

Tip: Looking for answers? Try searching our database.

Changing the properties of an Append Query in VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kou Vang - 04 Jan 2006 20:00 GMT
Is it possible in an Append Query, to change the table that is being
Appended, using VBA?  Can someone give me a quick idea of how to program that
snippet of code?  Thanks!
Klatuu - 04 Jan 2006 20:39 GMT
There are more than one way to do this.  Here is a simple solution:

Dim strSQL as String
Dim dbf as Database
Dim tdfs as TableDefs
Dim tdf as TableDef

'Set up object variables
   Set dbf = CurrentDb
   Set tdfs = dbf.TableDefs
   Set tdf = tdfs("MyQueryName")

'Get the SQL string for the query
   strSQL = tdf.SQL
'Replace the old name with the new name in the SQL
   strSQL = Replace(strSQL, "OldTableName", "NewTableName")

'Runs the append query with the selected table name
   dbf.Execute(strSQL)

'Note, we don't change the name in the original saved query so we don't know
what it is next time we need it.  The Execute method above is the same as
running the query any other way and is about 5 times faster than then RunSql
method.

'Destroy object variables
   Set tdf = Nothing
   Set tdfs = Nothing
   Set dbf = Nothing

> Is it possible in an Append Query, to change the table that is being
> Appended, using VBA?  Can someone give me a quick idea of how to program that
> snippet of code?  Thanks!
Roger Carlson - 04 Jan 2006 20:39 GMT
On my website (www.rogersaccesslibrary.com), is a small Access database
sample called "CreateQueries2.mdb" which illustrates how to do this.  All
the queries in the samples are Select queries, but the process is the same.
The SQL is just different.

Signature

--Roger Carlson
 Access Database Samples: www.rogersaccesslibrary.com
 Want answers to your Access questions in your Email?
 Free subscription:
 http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

> Is it possible in an Append Query, to change the table that is being
> Appended, using VBA?  Can someone give me a quick idea of how to program that
> snippet of code?  Thanks!
 
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.