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 / July 2005

Tip: Looking for answers? Try searching our database.

ALTER Table/UPDATE Syntax

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AnnMarie - 28 Jul 2005 18:29 GMT
Is it possible to pass a variable when using the ALTER Table and UPDATE
commands?  I've used the code below, which works when I specify the actual
table name and number for days, but states it can't find the table when I use
a variable.  I'm currently using Access 97.  Is there a specific syntax I
need to use to differentiate the variable names?

 DoCmd.TransferSpreadsheet acImport, 8, strTransFile, strInFile, False, ""
 DoCmd.RunSQL "ALTER TABLE strTransFile  ADD COLUMN Range Int", 0
 DoCmd.RunSQL "UPDATE ExcelTable SET Range = intDayRange", 0

I have three Excel files to import and depending on the specific file, the
intDayRange will be different for each file.  I'd like to use reuse the code
for each file.  After the updates I plan to append them to a main table.

Thanks!
Dirk Goldgar - 28 Jul 2005 18:48 GMT
> Is it possible to pass a variable when using the ALTER Table and
> UPDATE commands?  I've used the code below, which works when I
[quoted text clipped - 13 lines]
>
> Thanks!

You need to build the variable values, rather than their names, into the
SQL strings.  Like this:

 DoCmd.RunSQL "ALTER TABLE [" & strTransFile & "] ADD COLUMN Range
Int", 0
 DoCmd.RunSQL "UPDATE ExcelTable SET Range = " & intDayRange, 0

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Ken Sheridan - 28 Jul 2005 18:52 GMT
Concatenate the value of the variable into the string expression, e.g.

"ALTER TABLE " & strTransFile & " ADD COLUMN Range Int"

> Is it possible to pass a variable when using the ALTER Table and UPDATE
> commands?  I've used the code below, which works when I specify the actual
[quoted text clipped - 11 lines]
>
> Thanks!
Bas Cost Budde - 28 Jul 2005 18:54 GMT
> Is it possible to pass a variable when using the ALTER Table and UPDATE
> commands?  I've used the code below, which works when I specify the actual
[quoted text clipped - 4 lines]
>   DoCmd.TransferSpreadsheet acImport, 8, strTransFile, strInFile, False, ""
>   DoCmd.RunSQL "ALTER TABLE strTransFile  ADD COLUMN Range Int", 0

currentdb.execute "ALTER TABLE " & strTransFile & " ADD COLUMN Range Int"

>   DoCmd.RunSQL "UPDATE ExcelTable SET Range = intDayRange", 0

currentdb.execute "UPDATE ExcelTable SET Range = " & intDayRange

Signature

Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
For human replies, replace the queue with a tea

AnnMarie - 28 Jul 2005 20:35 GMT
Thanks so much for the speedy replies!  I ended up concantenating my original
code, but I also appreciate the examples of alternative methods.
 
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.