using InputBox

penfold1992

Registered User.
Local time
Today, 23:15
Joined
Nov 22, 2012
Messages
169
I would like to use an inputbox that accepts only a number between say... 1 and 100
The inputbox im using is just
Code:
s = InputBox("I think this is the content of the box", "Script Entry", "Enter the Number you wish to produce")
If s = "1" Then
m = MsgBox("Congrats", vbOKOnly, "title")
Else
m = MsgBox("Errorz", vbOKOnly, "title")
End If
its only as a test, the content doesnt really matter at the moment (all that matters is that it works!)

I dont know what controls what on InputBox ive never used it before (If I can move any parts of the box around... for a numeric value between 1 and 100 the "Input bar" is too long really.

The reasons I am using this rather then another form because I need to use some of the values that are in other areas of this current form and I am lazy and cant be bothered to re-route all of the values over to the new form to add them into a database when they are already there.

Ive tried looking at some information on the best way to do this but this is the best I can think of and honestly... I have no idea what im doing with it :p

hoping someone can offer some answers :)
 
but the pop up form would be ok if I could use the values from the current form without having to route them from that form to the new popup form
 
Did you want it for Excel and not Access?
This would Enforce a Number
Application.InputBox(prompt := "Sample", type := 1)

You can use the sum of the allowable values for Type. For example, for an input box that can accept both text and numbers, set Type to 1 + 2.
0 A formula
1 A number
2 Text (a string)
4 A logical value (True or False)
8 A cell reference, as a Range object
16 An error value, such as #N/A
64 An array of values

This example prompts the user for a number.
myNum = Application.InputBox("Enter a number")

This example prompts the user to select a cell on Sheet1. The example uses the Type argument to ensure that the return value is a valid cell reference (a Range object).
Worksheets("Sheet1").Activate
Set myCell = Application.InputBox( _
prompt:="Select a cell", Type:=8)
 
Note: Michael posted ahead of me - with another excellent suggestion.
For Access:
Dim Message, Title, Default, MyValue
Message = "Enter a value between 1 and 3" ' Set prompt.
Title = "InputBox Demo" ' Set title.
Default = "1" ' Set default.

No, Access won't allow the type to be set.
In a Pop-Up the existing form can provide values to the open Arg of the Pop-Up
Lets say you have a Customer_ID, Order_ID, and Order_Total on a form - these can be passed to a Pop-UP so it is all there in the pop-up form - to complete the shipping address.

We typically avoid the Input box because it just doesn't provide much until after the fact. That is, after the user enters something, the code can evaluate the input and suggest to try again. That is about it.

If you want to get information about a popup here is a downloadable demo:
http://www.access-programmers.co.uk/forums/showthread.php?t=227676&highlight=popup
 
if anyone cares.... this did the trick :)

Code:
s = InputBox("Please insert the number you wish to create.", _
"Batch Input Form", "Enter a number here")
If IsNumeric(s) = False Then
m = MsgBox("You must enter a number to create records.", vbOKOnly + 48, "Warning")
Else
l = s
If l <> Int(l) Then
m = MsgBox("Errorz", vbOKOnly, "title")
Else
m = MsgBox("Do not use your machine until you receive the next message.", _
vbOKOnly + vbCritical, "Creating Records...")
End If
End If

I think this could be a long winded way of doing things, I just dont know how I would code to reference the original form for values. This however does exactly what I want it to do so im happy with that
 
Last edited:
input box is a bit of a "blunt" instrument.

it's often better to design a better form than an input box.

i have only ever used input box a handful of times
 

Users who are viewing this thread

Back
Top Bottom