View Single Post
 
Old 03-19-2019, 05:57 PM
ScottyBee ScottyBee is offline Windows 10 Office 2016
Novice
 
Join Date: Mar 2019
Location: Portland, Oregon
Posts: 12
ScottyBee is on a distinguished road
Default Loop through Multiple Boolean Variables

Hello,


I am getting a "type mismatch" error when looping through Boolean variables trying to identify any variables that have a value of FALSE.



My code resides in a Module and is below:
Code:
Public txt1Changed As Boolean
Public txt2Changed As Boolean
Public txt3Changed As Boolean
Public txt4Changed As Boolean
Public txt5Changed As Boolean
Public txt6Changed As Boolean
Public txt7Changed As Boolean
Public txt8Changed As Boolean
Public cbo1Changed As Boolean
Public cbo2Changed As Boolean
Public cbo3Changed As Boolean



Public Sub Test()
    txt1Changed = True
    txt2Changed = True
    txt3Changed = True
    txt4Changed = True
    txt5Changed = True
    txt6Changed = True
    txt7Changed = False
    txt8Changed = True
    Dim i As Integer
      For i = 1 To 8
            If ("txt" & CStr(i) & "Changed") = False Then
                MsgBox ("Textbox " & i & " has not been changed.")
                '.SetFocus
                Exit Sub
            End If
      Next i
End Sub
Once I get this to work, I will be applying this to a VBA form that validates that all fields on a form have been changed before allowing the user to submit the data.


Thanks for any help

Last edited by Charles Kenyon; 03-26-2019 at 06:51 AM. Reason: Mark as solved
Reply With Quote