Renaming a Form object in VBA...

thewiseguy

Registered User.
Local time
Today, 05:36
Joined
Apr 14, 2004
Messages
56
Is it possible to rename a form object in code...?

I've tried using .Name but an error message will pop up saying this is only possible in Desgin mode...

...and .Rename does not operate on Form objects.

Cheers -
 
Like this?

Code:
DoCmd.Rename "NewName", acForm, "OldName"

Regards

Willi
 
crap - sorry - i explained myself badly!

i meant objects within a form like text/combo boxes.
not the form itself.

sorry again.
 
Try this code:
Code:
Public Sub frmObjRename(frm As String, objOldName As String, _
    objNewName As String)

    DoCmd.OpenForm frm, acDesign
    Forms(frm).Controls(objOldName).Name = objNewName
    DoCmd.Close acForm, frm, acSaveYes

End Sub
For example, calling this with:
frmObjRename "MyForm","txtOld","txtNew"

...will change the name of the control named txtOld to txtNew on the form MyForm.
 
Ops, ok, sorry! :o

Once again:

Code:
    DoCmd.OpenForm "YourForm", acDesign
    Forms!YourForm.OldName.Name = "NewName"
    DoCmd.Close acForm, "YourForm", acSaveYes

Do we got it now?

Willi
 
gracias amigos!

cheers guys - much appreciated :)

i haven't implemented the code yet, but will it cause windows to momentarily flash open and close or is it so quick that you won't see anything?
 
Think it's dependend from what is in foreground... :cool:

Willi
 
Use the Echo command to turn off the screen updating [flashing] for when the form is closed/opened. Just ensure that you turn the Echo off when done and that you add a command to turn Echo off in the error routine of your code!
 
it's working :love::love::love:
Tnx
first you need
Code:
Public frm, objOldName, objNewName
''remember you cant use me.form.name''

Public Sub test1(frm As String, objOldName As String, objNewName As String)
    DoCmd.OpenForm frm, acDesign
    Forms(frm).Controls(objOldName).Name = objNewName
    DoCmd.Close acForm, frm, acSaveYes

End Sub
 
it's working :love::love::love:
Tnx
first you need
Code:
Public frm, objOldName, objNewName
''remember you cant use me.form.name''

Public Sub test1(frm As String, objOldName As String, objNewName As String)
    DoCmd.OpenForm frm, acDesign
    Forms(frm).Controls(objOldName).Name = objNewName
    DoCmd.Close acForm, frm, acSaveYes

End Sub
Hi. Welcome to AWF!

Just FYI, this is an almost 20-year old thread. :)
 
''remember you cant use me.form.name''
That's because that references the active form. and since the form you are changing has to be open in design view, it can't be running code

I really hope that you are doing this to make a utility to help yourself. This is NOT something that should EVER happen in a database you are building for someone else to use.
 

Users who are viewing this thread

Back
Top Bottom