I have a whole bunch of buttons on a form which open a second form, create, a new record, etc, and fill it out with information from the original form. For instance, clicking button a1b would create a new record in a different table with the data from dropdown a1d and the caption of the label a1l.caption. This code works perfectly so far. However, I need to replicate it and change the a1 to about 100 other identifiers. I've named everything consistently, so b3b matches up with b3d and b3l.caption, etc. I was planning on creating one sub that calls up the form and inputs all the information and then calling that sub from within individual subs for each button. I tried have the sub for each button click be something like
And then in OpenNewForm replacing all the a1l and a3d, etc with StrName. So, referring to the caption of a1l would be [forms]![report]![StrName &_ "l"].caption . But that hasn't worked. I've also tried making it a variant instead. I'm not sure if the first sub that's the problem or the way in which I reference it in the OpenNewForm sub that's common to all the buttons. Any help would be appreciated.
Code:
Private Sub a1b_click()
Dim StrName as String
StrName = "a1"
Call OpenNewForm
End Sub
And then in OpenNewForm replacing all the a1l and a3d, etc with StrName. So, referring to the caption of a1l would be [forms]![report]![StrName &_ "l"].caption . But that hasn't worked. I've also tried making it a variant instead. I'm not sure if the first sub that's the problem or the way in which I reference it in the OpenNewForm sub that's common to all the buttons. Any help would be appreciated.