Can I do a loop in this case?

brave07124

Registered User.
Local time
Today, 07:06
Joined
Dec 26, 2013
Messages
11
Hi

Please find attached the database. View attachment ModuleSelection.accdb
Under the subroutine - Private Sub Command1_Click() , I use 14 If ... then statements.
I originally wanted to use a loop to do the job. But I cannot see how.
Can anyone see how a loop statement can be constructed or how to shorten the tediously long code?

Kind regards
 
When you put the module no. in the Tag property for each control, then you can reduce the code length.

Code:
Private Sub Command1_Click()
  Dim n As Integer, x As Integer
  Dim Student As String
  Dim Module As String
  Student = Text1.Value
  
  For x = 1 To 14
    If Me("Option" & CStr(x)) Then
     Call AddData(Student, Me("Option" & CStr(x)).Tag)
    End If
  Next
End Sub
And if the Module no. is a continuous number like you have here, then you don't need to put in a number in the Tag.

Code:
Call AddData(Student, "13BSC0" & Format(CStr(x), "00"))
 
Last edited:

Users who are viewing this thread

Back
Top Bottom