I have a template that, depending on the code number the user enters in the dialog box, will insert the appropriate document based on that number. There are 30 different documents. These documents will each have their own user form with a variety of questions the user needs to answer (ranging anywhere from 5 to 30 questions per document). These questions will be answered using option buttons. These option buttons are named the same for each document. i.e., for question 1 the option buttons would be optWCba1 (below average Question 1), optWCa1 (average Question 1) optWCaa1 (above average question 1) and optWCne1 (not evaluated Question 1). For question 2 they are written optWCba2, optWCa2, optaaWC2, optneWC2, etc.
Whatever option button the user chooses in the dialog box, the corresponding checkbox is checked on the document form.
If the user needs to make a change to the document they need to redisplay the userform. I need for the initialize to reselect the correct option button depending on the value of the checkbox on the form..
I want to use a VARIABLE NAME in lieu of the option button name in the Initialize below.
Example - In lieu of the option button name Me.optWCba1, I want to use a variable name so that I can increment the last digit by 1 each time the loop is run.
These's probably a much easier way to write all this, but I've never had a need to do anything this big that I need to cut down on the code as much as possible.
Private Sub UserForm_Initialize()
Dim varNumberWCQuestions
Select Case varWhatNAICSCode
Case 235710
varNumberWCQuestions = 11
varNumberGLQuestions = 8
Case 212312
varNumberWCQuestions = 9
varNumberGLQuestions = 8
Case 213111
varNumberWCQuestions = 3
varNumberGLQuestions = 5
End Select
'---- WC QUESTIONS
Dim myInitializeWCNum, varInitializeWhatWCQuestion
myInitializeWCNum = 1
'---- RUN LOOP UNTIL myWCNum IS GREATER THAN THE NUMBER OF QUESTIONS ESTABLISHED ABOVE IN THE SELECT CASE
Do Until myInitializeWCNum > varNumberWCQuestions
varInitializeWhatWCQuestion = "InitializeQuestionWC" & myInitializeWCNum
Application.Run MacroName:=varInitializeWhatWCQuestion
If varWCba = True Then
Me.optWCba1 = 1
ElseIf varWCa = True Then
Me.optWCa1 = 1
ElseIf varWCaa = True Then
Me.optWCaa1 = 1
Else
Me.optWCne1 = 1
End If
myInitializeWCNum = myInitializeWCNum + 1
Loop
End Sub
THIS IS WRITTEN IN A SEPARATE MODULE THAT EACH OF THE FORMS CAN CALL
Sub WCbaChosen()
varWCne = False
varWCba = True
varWCa = False
varWCaa = False
End Sub
Sub WCaChosen()
varWCne = False
varWCba = False
varWCa = True
varWCaa = False
End Sub
Sub WCaaChosen()
varWCne = False
varWCba = False
varWCa = False
varWCaa = True
End Sub
Sub WCneChosen()
varWCne = True
varWCba = False
varWCa = False
varWCaa = False
End Sub
' ---- WC 1
Sub InitializeQuestionWC1()
If ActiveDocument.FormFields("cbWCba1").Result = 1 Then
Call WCbaChosen
End If
If ActiveDocument.FormFields("cbWCa1").Result = 1 Then
Call WCaChosen
End If
If ActiveDocument.FormFields("cbWCaa1").Result = 1 Then
Call WCaaChosen
End If
If ActiveDocument.FormFields("cbWCne1").Result = 1 Then
Call WCneChosen
End If
End Sub
' ---- WC 2
Sub InitializeQuestionWC2()
If ActiveDocument.FormFields("cbWCba2").Result = 1 Then
Call WCbaChosen
End If
If ActiveDocument.FormFields("cbWCa2").Result = 1 Then
Call WCaChosen
End If
If ActiveDocument.FormFields("cbWCaa2").Result = 1 Then
Call WCaaChosen
End If
If ActiveDocument.FormFields("cbWCne2").Result = 1 Then
Call WCneChosen
End If
End Sub
Whatever option button the user chooses in the dialog box, the corresponding checkbox is checked on the document form.
If the user needs to make a change to the document they need to redisplay the userform. I need for the initialize to reselect the correct option button depending on the value of the checkbox on the form..
I want to use a VARIABLE NAME in lieu of the option button name in the Initialize below.
Example - In lieu of the option button name Me.optWCba1, I want to use a variable name so that I can increment the last digit by 1 each time the loop is run.
These's probably a much easier way to write all this, but I've never had a need to do anything this big that I need to cut down on the code as much as possible.
Private Sub UserForm_Initialize()
Dim varNumberWCQuestions
Select Case varWhatNAICSCode
Case 235710
varNumberWCQuestions = 11
varNumberGLQuestions = 8
Case 212312
varNumberWCQuestions = 9
varNumberGLQuestions = 8
Case 213111
varNumberWCQuestions = 3
varNumberGLQuestions = 5
End Select
'---- WC QUESTIONS
Dim myInitializeWCNum, varInitializeWhatWCQuestion
myInitializeWCNum = 1
'---- RUN LOOP UNTIL myWCNum IS GREATER THAN THE NUMBER OF QUESTIONS ESTABLISHED ABOVE IN THE SELECT CASE
Do Until myInitializeWCNum > varNumberWCQuestions
varInitializeWhatWCQuestion = "InitializeQuestionWC" & myInitializeWCNum
Application.Run MacroName:=varInitializeWhatWCQuestion
If varWCba = True Then
Me.optWCba1 = 1
ElseIf varWCa = True Then
Me.optWCa1 = 1
ElseIf varWCaa = True Then
Me.optWCaa1 = 1
Else
Me.optWCne1 = 1
End If
myInitializeWCNum = myInitializeWCNum + 1
Loop
End Sub
THIS IS WRITTEN IN A SEPARATE MODULE THAT EACH OF THE FORMS CAN CALL
Sub WCbaChosen()
varWCne = False
varWCba = True
varWCa = False
varWCaa = False
End Sub
Sub WCaChosen()
varWCne = False
varWCba = False
varWCa = True
varWCaa = False
End Sub
Sub WCaaChosen()
varWCne = False
varWCba = False
varWCa = False
varWCaa = True
End Sub
Sub WCneChosen()
varWCne = True
varWCba = False
varWCa = False
varWCaa = False
End Sub
' ---- WC 1
Sub InitializeQuestionWC1()
If ActiveDocument.FormFields("cbWCba1").Result = 1 Then
Call WCbaChosen
End If
If ActiveDocument.FormFields("cbWCa1").Result = 1 Then
Call WCaChosen
End If
If ActiveDocument.FormFields("cbWCaa1").Result = 1 Then
Call WCaaChosen
End If
If ActiveDocument.FormFields("cbWCne1").Result = 1 Then
Call WCneChosen
End If
End Sub
' ---- WC 2
Sub InitializeQuestionWC2()
If ActiveDocument.FormFields("cbWCba2").Result = 1 Then
Call WCbaChosen
End If
If ActiveDocument.FormFields("cbWCa2").Result = 1 Then
Call WCaChosen
End If
If ActiveDocument.FormFields("cbWCaa2").Result = 1 Then
Call WCaaChosen
End If
If ActiveDocument.FormFields("cbWCne2").Result = 1 Then
Call WCneChosen
End If
End Sub