- Local time
- Today, 16:37
- Joined
- Feb 19, 2002
- Messages
- 45,774
There are always unintended consequences when Jet/ACE and VBA collide. In order to conform to SQL standards, Access needed to allow special characters and embedded spaces in table and column names. However, programming languages are persnickety about how object names are formed. MS got around this with VBA by using the square brackets BUT, that doesn't solve all problems. Look what you end up with if you try to add events to a control that starts with an underscore or contains other bad characters.
I added five bad names to a table:
_BadName
(BadName2
*BadName3
Bad(Name
Bad*Name
VBA prefixes the control name with "Ctl" because VBA does not allow leading special characters in names.
Notice how VBA changes the event names for the second two bad names. It still adds "Ctl" to the beginning but it also changes the * and the ( to an underscore because neither * nor ( are valid in variable names in VBA.
For the 4th and 5th, "Ctl" did not need to get prepended to the name but the special character was still invalid and so for #4, Access changed it to the underscore as normal. However, doing that for the 5th would create a duplicate name. Older versions of Access used to just increase the number of underscores so five would have been Bad__Name to distinguish it from Bad_Name. But this version has abandoned that and now just gives the control a number.
I added five bad names to a table:
_BadName
(BadName2
*BadName3
Bad(Name
Bad*Name
VBA prefixes the control name with "Ctl" because VBA does not allow leading special characters in names.
Notice how VBA changes the event names for the second two bad names. It still adds "Ctl" to the beginning but it also changes the * and the ( to an underscore because neither * nor ( are valid in variable names in VBA.
For the 4th and 5th, "Ctl" did not need to get prepended to the name but the special character was still invalid and so for #4, Access changed it to the underscore as normal. However, doing that for the 5th would create a duplicate name. Older versions of Access used to just increase the number of underscores so five would have been Bad__Name to distinguish it from Bad_Name. But this version has abandoned that and now just gives the control a number.
Code:
Private Sub Ctl_BadName_Click()
End Sub
Private Sub Ctl_BadName2_Click()
End Sub
Private Sub Ctl_BadName3_Click()
End Sub
Private Sub Bad_Name_Click()
End Sub
Private Sub Text50_Click()
End Sub
Last edited: