Exit inputbox after valid input (1 Viewer)

taball0829

New member
Local time
Today, 10:26
Joined
Feb 23, 2018
Messages
28
I would really like this inputbox to close automatically (AND it would be wonderful to get it to go to the next tabstop when closing) when there is a valid input.

OR, is there a better way to be able to input "b" or "v" into my GameX that must end up as an integer?

Private Sub Game1_GotFocus()
Dim str As String
str = InputBox("'b'lind" & Chr$(13) & Chr$(10) & "'v'acant" & Chr(13) & Chr$(10) & "or Score", "Enter Game 1")
If str = "b" Then
Me.Game1 = -(Me.current_avg - (Me.current_avg \ 10))
ElseIf str = "v" Then
Me.Game1 = -120
Else
Me.Game1 = Val(str)
End If
End Sub
 

bob fitz

AWF VIP
Local time
Today, 15:26
Joined
May 23, 2011
Messages
4,719
If you want to restrict user input "b" or "v", why not use a combo box.
 

taball0829

New member
Local time
Today, 10:26
Joined
Feb 23, 2018
Messages
28
The actual data that goes into the table is an integer. Entering a "b" into the field directly will produce an error, so I have to look for a "b" or a "v" and return the appropriate integer. Is that possible with a combo box? I thought a combo only listed information that is already in the field.
 

bob fitz

AWF VIP
Local time
Today, 15:26
Joined
May 23, 2011
Messages
4,719
Create a Value List for the combo box. Put your numeric value in the first column and the text value in the second column. Set the column width of the first column to zero which will hide it when viewed so the user will see the text values but the first column with the numeric value can be bound to a field in the form's table.
 

bob fitz

AWF VIP
Local time
Today, 15:26
Joined
May 23, 2011
Messages
4,719
If selection of a particular value in the combo list requires a calculation to be done, then you could make the combo unbound and do the required calculation and set the focus to another control by using a little code in the After Udate event of the combo. The attached db may be of some use:
 

Attachments

  • Combo ValueList Bob.accdb
    412 KB · Views: 56

Gasman

Enthusiastic Amateur
Local time
Today, 15:26
Joined
Sep 21, 2011
Messages
14,235
Bob,
How would you take into account the entry of an actual value, as that is the third option.?
 

bob fitz

AWF VIP
Local time
Today, 15:26
Joined
May 23, 2011
Messages
4,719
Bob,
How would you take into account the entry of an actual value, as that is the third option.?
Possibly with code in the NotInList event of the combo box, or perhaps by using a "Case" statement instead of the "If" that I used.
 

Users who are viewing this thread

Top Bottom