Skip to main content

Checking user Inputs for errors

I am working on putting more controls in place to check for user input errors when I am building dialog boxes that require user interaction. 
Right now I have a listing of checkboxes to allow the user to select which tests they would like to run.  Out of the five items I have, there are two that cannot both be selected.
Right now, after assigning true to the varriables assoicated with each test, I am trying to create a message box that would make it so the user cannot continue if both of those tests are selected.  I used the following simple If statement, however it will not let the user deselect one of the tests.
Case "CheckBox1"
Test1 = True
MsgBox Test1 will run
Case "CheckBox2"
Test2 = True
MsgBox Test2 will run
Case "CheckBox3"
Test3 = True
MsgBox Test3 will run
Case "CheckBox4"
Test4 = True
MsgBox Test4 will run
Case "CheckBox5"
Test5 = True
MsgBox Test5 will run
 
'If the user selects the Cancel Button, the dialog closes and end the script
Case "CancelButton1"
bExitFun = True
bExitScript = True
Case "OKButton1"
End Select
End Select
 
If Test4 = true Then
If Test5 = true Then
MsgBox Please only select Test 4 or Test 5
End If
End If
 

Brian Element Tue, 02/11/2020 - 21:23

Are you doing this within the DisplayIt function (the function that is used when the dialog is displayed) or after the dialog has been closed?  If you are using the DisplayIt function can you post the code for the entire function.

E.Heizyk Wed, 02/12/2020 - 12:36

Yes it is in the desplayIt function, here is the remainder:
Function displayIt(ControlID$, Action%, SuppValue%)
Dim db As Database
Dim button As Boolean
Dim bExitMenu As Boolean Dim bExitFun As Boolean
 
'these are actually defined outside of the displayIt function in order to use the results within the main.
Dim Test1 as Boolean
Dim Test2 as Boolean
Dim Test3 as Boolean
Dim Test4 as Boolean
Dim Test5 as Boolean
 
 
Select Case Action%
Case 1
Case 2
Select Case ControlID$
Case "CheckBox1"
Test1 = True
Case "CheckBox2" Test2 = True
Case "CheckBox3"
Test3 = True
Case "CheckBox4" Test4 = True
Case "CheckBox5"
Test5 = True
 
'If the user selects the Cancel Button, the dialog closes and end the script
Case "CancelButton1"
bExitFun = True
bExitScript = True
 
'When the user selects the OK button, route to the first test that they selected
Case "OKButton1"
If Test1 = True Then
button = Dialog(Test1Menu)
Call displayTest1Menu()
 
ElseIf Test2 = True Then
button = Dialog(Test2Menu)
Call displayTest2Menu()
 
ElseIf Test3 = True Then
button = Dialog(Test3Menu)
Call displayTest3Menu()
 
ElseIf Test4 = True Then
button = Dialog(Test4Menu)
Call displayTest4Menu()
 
ElseIf Test5 = True Then
button = Dialog(Test5Menu)
Call displyTest5Menu()
Else
 
MsgBox "none selected"
End If
End Select
End Select
 
If Test4 = true Then
If Test5 = true Then
MsgBox Please only select Test4 or Test5 
End If
End If
 
End Function

E.Heizyk Wed, 02/12/2020 - 17:50

Here is the full displayIt function:
Function displayIt(ControlID$, Action%, SuppValue%)
Dim db As Database
Dim button As Boolean
Dim bExitMenu As Boolean
Dim bExitFun As Boolean
 
Select Case Action%
Case 1
Case 2
Select Case ControlID$
Case "CheckBox1"
Test1 = True
Case "CheckBox2"
Test2 = True
Case "CheckBox3"
Test3 = True
Case "CheckBox4"
Test4 = True
Case "CheckBox5"
Test5 = True
 
'If the user selects the Cancel Button, the dialog closes and end the script
Case "CancelButton1"
bExitFun = True
bExitScript = True
 
'When the user selects the OK button, route to the first test that they selected
Case "OKButton1"
If Test1 = True Then
button = Dialog(Test1Dlg)
Call displayTest1Menu()
 
ElseIf Test2 = True Then
button = Dialog(Test2Dlg)
Call displayTest2Menu()
 
ElseIf Test3 = True Then
button = Dialog(Test3Dlg)
Call displayTest3Menu()
 
ElseIf Test4 = True Then
button = Dialog(Test4Dlg)
Call displayTest4Menu()
 
ElseIf Test5 = True Then
button = Dialog(Test5Dlg)
Call displayTest5Menu()
Else
 
MsgBox "none selected"
End If
End Select
End Select
 
If Test4 = true Then
If Test5 = true Then
MsgBox Please select Test 4 or Test 5, both cannot be run.
End If
End If