?
Solved

Validate data in an inputbox

Posted on 2007-11-20
2
Medium Priority
?
529 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
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!
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

800 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