Validate data in an inputbox

Posted on 2007-11-20
Medium Priority
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.

    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

Question by:TylerDerden

Accepted Solution

geekspeaknow earned 1000 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!
LVL 10

Expert Comment

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


Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
A quick solution showing how to control and open a POS Cash Register Drawer using VBA with MS Access.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

597 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