Delete name label

G

giorgio

How can i delete name or part of it (_label) of label using the vba
method-code ?
thanks
 
B

Brendan Reynolds

There's a potential issue to watch for here. If there is a textbox on the
form called "Whatever" and a label called "Whatever_label", this code would
fail, because the result would be two controls with the same name, and
control names must be unique within the parent form.

Public Sub RenameLabels()

Dim ctl As Control
Dim lngPos As Long

DoCmd.OpenForm "Categories", acDesign
For Each ctl In Forms("Categories").Controls
If ctl.ControlType = acLabel Then
lngPos = InStr(1, ctl.Name, "_label")
If lngPos > 0 Then
ctl.Name = Left$(ctl.Name, lngPos - 1)
End If
End If
Next ctl

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
B

Brendan Reynolds

Does it really say 'ctl is in use'? Or does it really say 'Run-time error
'2104': You entered the control name' <actual name of your control without
'_label' here>,' which is already in use.'

If the later, that's the potential issue that I warned you about in my
original reply. If you have a control named 'Whatever' and another control
named 'Whatever_label' you can not simply strip the '_label' from the second
control, because you would then have two controls with the same name, and
Access won't allow that.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
G

giorgio

Thanks for advice.
I add a prefix before.
Regards
Brendan Reynolds said:
Does it really say 'ctl is in use'? Or does it really say 'Run-time error
'2104': You entered the control name' <actual name of your control without
'_label' here>,' which is already in use.'

If the later, that's the potential issue that I warned you about in my
original reply. If you have a control named 'Whatever' and another control
named 'Whatever_label' you can not simply strip the '_label' from the
second control, because you would then have two controls with the same
name, and Access won't allow that.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Top