Rename a table

G

Guest

I'm trying to rename a table in my current database using a module attached
to a command button, using the DoCmd object, like so:

Private Sub Befehl70_Click()
On Error GoTo Err_Befehl70_Click


DoCmd.Rename Application!CurrentData!AllTables!diff_gnl_old, acTable,
Application!CurrentData!AllTables!diff_gnl_new
DoCmd.OpenForm Pegel_edit, acNormal

Exit_Befehl70_Click:
Exit Sub

Err_Befehl70_Click:
MsgBox Err.Description
Resume Exit_Befehl70_Click

End Sub

In the database window, if I click on 'Tables' and rename diff_gnl_new to
diff_gnl_old, it works fine - I just need to confirm that I want to replace
the old version of diff_gnl_old, and it's done.

However, when I try to use my command button, with the above code in its
module, I get an error message saying that the 'object does not support this
feature or method' - or whatever the English translation is of the message
which I'm getting in German. Is it a problem with how I've referenced the
table in my code (I'm not an expert on the hierarchy of objects), or is there
something I need to add to my code?

Thanks
Mike M
 
A

Andi Mayer

I'm trying to rename a table in my current database using a module attached
to a command button, using the DoCmd object, like so:

Private Sub Befehl70_Click()
On Error GoTo Err_Befehl70_Click


DoCmd.Rename Application!CurrentData!AllTables!diff_gnl_old, acTable,
Application!CurrentData!AllTables!diff_gnl_new
DoCmd.OpenForm Pegel_edit, acNormal

Exit_Befehl70_Click:
Exit Sub

Err_Befehl70_Click:
MsgBox Err.Description
Resume Exit_Befehl70_Click

End Sub

out of the helpfile:
DoCmd.Rename newname[, objecttype, oldname]

therefore:
DoCmd.Rename diff_gnl_new, acTable, diff_gnl_old

if diff_gnl_new is the name of the new Table
 
G

Guest

Thanks for the reply,

I already tried it in that format, and I got a message saying 'For this
action, the argument 'Object Name' is required', That was why my code had,
for example, 'Application!CurrentData!AllTables!diff_gnl_old', instead of
just 'diff_gnl_old'. I'm still not sure that I'm referring the DoCmd.Rename
command to the right table...

And I should also say please ignore the line saying ' DoCmd.OpenForm
Pegel_edit, acNormal ' - this was an error.
 
A

Andi Mayer

Thanks for the reply,

I already tried it in that format, and I got a message saying 'For this
action, the argument 'Object Name' is required', That was why my code had,
for example, 'Application!CurrentData!AllTables!diff_gnl_old', instead of
just 'diff_gnl_old'. I'm still not sure that I'm referring the DoCmd.Rename
command to the right table...

And I should also say please ignore the line saying ' DoCmd.OpenForm
Pegel_edit, acNormal ' - this was an error.

if diff_gnl_old is the real name of the table (not a variable with the
tablename) then you have to put it into quotes (docmd.rename want's a
string)
 
J

John Nurick

PMFJI, Mike, but if routine operation of your application requires the
renaming of tables, there's almost certainly something amiss with your
data structure.
 
G

Guest

Andi, thanks for the help!

John, you are without doubt right - my Access/VBA knowledge is very much a
work-in-progress, and at the moment I'm just happy that it works as-is and
gets the job done.... I'm learning as I go!

Thanks
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top