Solved

Validate data in an inputbox

Posted on 2007-11-20
2
523 Views
Last Modified: 2013-11-27
I think I'm making this harder than what it is.
I would like to prompt the user for an integer that represents a month. Ex - 9 for September
and have some data validation. However, I seem to be caught in the if statement.

Suggestions are greatly appreciated.


Do

   

    Check = False

    

    If ReportMonthInt < 1 Or ReportMonthInt > 12 Then

    

     Check = True

     

     MsgBox "Please enter a valid integer value for a month between 1 and 12.", vbOKCancel

      If vbOKCancel = 2 Then

       Exit Sub

       End If

      

     ReportMonth = InputBox("Enter the numeric month to query?", "Report Month", DefaultMonth)

      If ReportMonth = "" Then

       Exit Sub

       End If

        

     Else: Check = False

     

    End If

   

 Loop While Check = True

Open in new window

0
Comment
Question by:TylerDerden
2 Comments
 
LVL 2

Accepted Solution

by:
geekspeaknow earned 250 total points
ID: 20321761
I would do this within the properties part of the combo box.  Right click on the combo box and go to Properties, go to the Data tab.  The 3rd choice of Row Source Type, pick Value List.  In Row Source, Type 1;2;3;4;5;6;7;8;9;10;11;12 (You would need code for a longer list, but this should work for what you need).  Then change the Limit To List box to Yes.  Let me know if this works for you.  Thanks!
0
 
LVL 10

Expert Comment

by:LennyGray
ID: 20322305
See the attachment
Public Function FigureTheMonth(sTheMonth As Variant)

Dim bStatus As Boolean
 

    

    Select Case CInt(nz(sTheMonth, 0))

        Case 1 To 12

            bStatus = True

        Case Else

            bStatus = False

    End Select
 

MsgBox "Status = " & bStatus

    

End Function

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now