I am trying to make multiple copies of a VBA on click events using a sqlstring (see below). ~10K copies
For the most part all is well. Although what I would like to happen is for the CreateCode2 mod to create only the Private Sub () when the cpt (5digitnumber) is listed in the tblValue.
What is happening: my variable i = 11001 to 11020 creates 20 Public Sub btn5ditignumber_Click()
What I want to happen: Create only the 5 Public Sub btn5didigitnumber_Click () based on the existing values in the cpt field in tblValues.
What I am hoping is an if statement or something else that would evaluate the i = 11001 to 11020 and therefore create on the 5 wanted Private Sub btn5digitnumber_Click ()
All suggestion would be appreciated.
and thanks very much in advance.
Two tables
tblValues 4 fields Id autoenter, CPT as number long, des as text and RVU as double
the cpt value is the 5digitnumber.
tblValue ID cpt des rvu 1 11001 this is text1 1.1 2 11003 this is text2 1.2 3 11005 this is text3 1.3 4 11010 this is text4 1.4 5 11020 this is text5 1.5
tblMemo 2 fields id number autoenter and a text field called Memo as text long
Below is the appearance of tblMemo after running CreateCode2
tblMemo ID Memo 1 Private Sub btn11002_Click()
Code written here
End Sub
Private Sub btn11003_Click()
Code written here
End Sub
Private Sub btn11004_Click()
Code written here
End Sub
Private Sub btn11005_Click()
Code written here
End Sub
Private Sub btn11006_Click()
Code written here
End Sub
Private Sub btn11007_Click()
Code written here
End Sub
Private Sub btn11008_Click()
Code written here
End Sub
Private Sub btn11009_Click()
Code written here
End Sub
Private Sub btn11010_Click()
Code written here
End Sub
Private Sub btn11011_Click()
Code written here
End Sub
Private Sub btn11012_Click()
Code written here
End Sub
Private Sub btn11013_Click()
Code written here
End Sub
Private Sub btn11014_Click()
Code written here
End Sub
Private Sub btn11015_Click()
Code written here
End Sub
Private Sub btn11016_Click()
Code written here
End Sub
Private Sub btn11017_Click()
Code written here
End Sub
Private Sub btn11018_Click()
Code written here
End Sub
Private Sub btn11019_Click()
Code written here
End Sub
Private Sub btn11020_Click()
Code written here
End Sub
Private Sub btn11021_Click()
Code written here
End Sub
The name of the button will be btn5digitnumber_Click()
‘below is the mod that creates the code in the tblMemo
Public Sub CreateCode2()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Long
Dim strMemo As String
Set db = CurrentDb
Set rs = db.OpenRecordset("Select * FROM tblMemo WHERE [ID]=1")
With rs
For i = 11001 To 11020
strMemo = strMemo & "Private Sub btn" & CStr(i + 1) _
& "_Click()" & vbNewLine _
& "Code written here" & vbNewLine _
& "End Sub" & vbNewLine & vbNewLine
Next i
.Edit
.Fields("Memo") = strMemo
.Update
.Close
End With
Set db = Nothing
Set rs = Nothing
End Sub