Solved Cycling Through Selects (1 Viewer)

pooldead

Registered User.
Local time
Today, 13:46
Joined
Sep 4, 2019
Messages
136
I have some code to update table information. All it is in input boxes and sql statements. Let's say I have an input box that I specify they enter either True or False. IF they enter something different, how would I cycle the code back to the original input box so they could change their response? Using Select Case...Case Else
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:46
Joined
Oct 29, 2018
Messages
21,454
Can you show us your code? If you only want the user to enter True or False, then why not use a Combobox?
 

isladogs

MVP / VIP
Local time
Today, 21:46
Joined
Jan 14, 2017
Messages
18,209
Or an option group or a checkbox.
The principle is that users should not be able to make choices that aren't valid.
 

Isaac

Lifelong Learner
Local time
Today, 13:46
Joined
Mar 14, 2017
Messages
8,777
You're talking about actual InputBox functions, right? Where you have several InputBoxes collecting information, but then based on a latter one, you want to go back and 'change' a former one, essentially?

Well, without comment as to whether this is necessarily the best way to do it, something like this:

Code:
Dim strAnswer1 As String, strAnswer2 As String, strAnswer3 As String

strAnswer1 = InputBox("Answer 1")
strAnswer2 = InputBox("Answer2")
strAnswer3 = InputBox("Answer 3")

If strAnswer3 = "something particular" Then
    strAnswer1 = InputBox("Answer #1 again please")
End If

But I agree with previous answers ... Requirements tend to outlast InputBox's functionalities/usefulness very quickly, and might as well generally be skipped. Create a UI to handle
 
Last edited:

pooldead

Registered User.
Local time
Today, 13:46
Joined
Sep 4, 2019
Messages
136
Code:
            appChoice = InputBox("Enter the numeric value for the appropriate selection below to proceed:" & vbNewLine & vbNewLine & _
                                    "1 - Modify ALL roles for an application" & vbNewLine & _
                                    "2 - Modify LOCATION-BASED roles for an application", "Roles to be Modified")
            Select Case appChoice
                        Case Is = 1
                              'Do Something
                        Case Is = 2
                              'Do Something
                        Case Else
                            MsgBox "Option " & appChoice & " is not supported. Please re-enter the value.", vbExclamation + vbRetryCancel, "Not Supported"
                    End Select
So that is a slimmed-down version of my code. But the input value they provide will be used to update multiple records at once. In this example, it isn't True or False, but rather #1 or #2. What I'm curious about is if they enter "3" into the appChoice input box, if the code can start over from the beginning with appChoice again, in order to let them modify their selection.
 

Isaac

Lifelong Learner
Local time
Today, 13:46
Joined
Mar 14, 2017
Messages
8,777
What I'm curious about is if they enter "3" into the appChoice input box, if the code can start over from the beginning with appChoice again, in order to let them modify their selection.
I see.

See my earlier post. You would have to basically test for a condition, and if true, simply re-run the InputBox and assign it to a variable.

Code:
  appChoice = InputBox("Enter the numeric value for the appropriate selection below to proceed:" & vbNewLine & vbNewLine & _
                                    "1 - Modify ALL roles for an application" & vbNewLine & _
                                    "2 - Modify LOCATION-BASED roles for an application", "Roles to be Modified")
            Select Case appChoice
                        Case Is = 1
                              'Do Something
                        Case Is = 2
                              'Do Something
                        Case Else
                            MsgBox "Option " & appChoice & " is not supported. Please re-enter the value.", vbExclamation + vbRetryCancel, "Not Supported"
                            appChoice = InputBox("Enter the numeric value for the appropriate selection below to proceed:" & vbNewLine & vbNewLine & _
                                    "1 - Modify ALL roles for an application" & vbNewLine & _
                                    "2 - Modify LOCATION-BASED roles for an application", "Roles to be Modified")
                    End Select
                    'nesting a further case statement here - allows for a mistake to be made 1 time.. I really don't recommend trying to design this way. Create an interface that validates a final thumbs up or down.

If you REALLY wanted to accommodate the possibility that they keep making the wrong choice over and over, and allow them to keep running the code to try again, into infinity, you could use a combination of line labels and GoTo statements. But I wouldn't even come as close to recommending that as it would take to post a sample....Total thumbs down on that method.
 

Users who are viewing this thread

Top Bottom