Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can one force to add a value in a  inputbox on microsoft access 2013

Posted on 2014-02-12
3
Medium Priority
?
775 Views
Last Modified: 2014-02-12
hi

i have a form in microsoft access that when i press on a button it's opening an iputbox that ask "what is the value ". and i want to force the user to put the value 1 or 2, and if he don't enter it this will show up an msgbox that he must to put a value between 1-2, and when he will press ok  the inpubx will show up again like an endless loop, and the user can stop it only when he press on the cancel on the inputbox button


dim a as long
a = clng(inpubox("press a value between 1-2")
if not a>0 or not a <3 then
msgbox "you must ot enter a value between 1-2
inputbox again

Open in new window

0
Comment
Question by:bill201
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1000 total points
ID: 39854513
Dim a As Long
Do
a = CLng(InputBox("press a value between 1-2"))
     If Not a > 0 Or Not a < 3 Then
          MsgBox "you must enter a value between 1-2"
          Else
          Exit Do
     End If
Loop
0
 
LVL 49

Assisted Solution

by:Dale Fye
Dale Fye earned 1000 total points
ID: 39854527
Although I generally frown on the use of inputbox, preferring forms for entering critical information like this, the only way to "force" a valid entry is to do it within a loop like Rey has recommended.

When I do this, I generally add a loop counter and after the user incorrectly enters a value 3 times, I present them with a different message and then force them out of the procedure that needed that value.
0
 

Author Closing Comment

by:bill201
ID: 39854583
thanks a lot
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question