Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use variables with CopyObject 2

Status
Not open for further replies.

swtrader

IS-IT--Management
Dec 23, 2004
182
0
0
US
If I hardcode the table names, the code runs. However, I need to use varibles for table names. What is the proper syntax to be able to use variables?

Thank you.




Private Sub Command18_Click()

Dim tblFileName_BU2 As String 'old table
Dim tblFileName_BU3 As String 'new table

newtable = tblFileName_BU3
oldtable = tblFileName_BU2


DoCmd.Rename newtable, acTable, oldtable

End Sub
----- OR -------

This works but I need variables....

Private Sub Command19_DblClick(Cancel As Integer)
DoCmd.CopyObject , "tblFileNames_BU1", acTable, "tblFileNames_BU2"
End Sub
 
Dim OldTableName as string
Dim NewTableName as string

OldTableName = "tblFileName_BU2"
NewTableName ="tblFileName_BU3"
DoCmd.Rename NewTableName , acTable, OldTableName
docmd.CopyObject ,NewTableName , acTable, OldTableName





 
1)
newtable = "tblFileName_BU3"
oldtable = "tblFileName_BU2"
DoCmd.Rename newtable, acTable, oldtable

2)
newtable = "tblFileNames_BU1"
oldtable = "tblFileNames_BU2"
DoCmd.CopyObject , newtable, acTable, oldtable


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Great. Thanks.

Here's what I needed:


Dim OldTableName as string
Dim NewTableName as string
OldTableName = "tblFileName_BU2"
NewTableName ="tblFileName_BU3"
DoCmd.CopyObject ,NewTableName , acTable, OldTableName

this keeps the old table and creates a new one
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top