Use Command button to rename on fly

K

Kellie

I am trying to get a command button to do a rename,
however, I do not want to have a pre-determined name...I
want to choose the name on the fly.

Ex. I know you can do a rename by doing an [Event
Procedure]...
DoCmd.Rename "New Name", acTable, "Old Name"

I do not want to pick the new name. I want a box to come
up and the user will type in the name they want the table
to change to.

Is this possible????
Thank You
 
D

Dirk Goldgar

Kellie said:
I am trying to get a command button to do a rename,
however, I do not want to have a pre-determined name...I
want to choose the name on the fly.

Ex. I know you can do a rename by doing an [Event
Procedure]...
DoCmd.Rename "New Name", acTable, "Old Name"

I do not want to pick the new name. I want a box to come
up and the user will type in the name they want the table
to change to.

Is this possible????
Thank You

You could use something along these lines:

Dim strNewNama As String

strNewName = InputBox("Enter a new name:")

If Len(strNewName) > 0 Then
DoCmd.Rename strNewName, acTable, "Old Name"
End If

Of course, that will raise an error if the new name already exists.
 
M

Mark Phillipson

Hi,

You could use the InputBox function.

Code would have to make sure that a name is entered:

Dim strName As String
strName = ""
Do Until Len(strName) > 0
strName = InputBox("Please Enter the new table name", _
"Rename Example", "tblSomeTable")
Loop
DoCmd.Rename strName, acTable, "tblSomeTable"

HTH

--

Cheers
Mark

Free Access/Office Add-Ins at:
http://mphillipson.users.btopenworld.com/
 

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

Top