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 2007

Tip: Looking for answers? Try searching our database.

Alter Table - VB Approach

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Whelan - 25 Jan 2007 11:32 GMT
Hey Guys,

I have an SQL Alter Table statment which removes two columns from a table.

However, the name of the table changes daily (the date is added onto the
end). Is there anyway of incorporating a Variable for the name within the SQL
Code?

I can't seem to find away of achieving this so far. Here's the code which
obviously doesn't work at the moment, due to the variable being used as the
table name.

Function AmendTodaysNameChanges()

Dim Table As String

TableNAME = "Name Changes Report" & Format(Date - 1, "dd-mm-yyyy")

   Dim strSQLRemoveColumns As String
   DoCmd.SetWarnings False
       strSQLRemoveColumns = "Alter table [tablename] Drop Column
id,adt,dateid;"
   DoCmd.RunSQL strSQLRemoveColumns
   DoCmd.SetWarnings True

End Function
BeWyched - 25 Jan 2007 13:01 GMT
Change:

strSQLRemoveColumns = "Alter table [tablename] Drop Column
id,adt,dateid;"

to:

strSQLRemoveColumns = "Alter table " & TableNAME & " Drop Column
id,adt,dateid;"

Good luck.

BW

> Hey Guys,
>
[quoted text clipped - 22 lines]
>
> End Function
BeWyched - 25 Jan 2007 13:04 GMT
Sorry, I forget the []'s ! - use:

strSQLRemoveColumns = "Alter table [" & TableNAME & "] Drop Column
id,adt,dateid;"

> Change:
>
[quoted text clipped - 36 lines]
> >
> > End Function
Whelan - 25 Jan 2007 14:05 GMT
BeWyched, that is ruddy brilliant.

Thank you very much!!

Tom

> Sorry, I forget the []'s ! - use:
>
[quoted text clipped - 41 lines]
> > >
> > > End Function
 
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.