NOOB.. error validation question

brumshine

Registered User.
Local time
Today, 13:35
Joined
Dec 17, 2008
Messages
37
I would like to do some simple error validation on a form of mine. Basically compare two input boxes and if box1 is greater than box2 display an error message then bring the user back to the form so that they can fix it. I just need to exit the function and go back to the form.

What am I missing?

Thanks in advance

BRUMSHINE
 
As Paul has said, this is a job for Form_BeforeUpdate Man! The question, of course, is which textbox do you want to return focus to? The invalid situation could be corrected by changing either data in either textbox!
 
Baldy, you the man. That was exactly what I needed. That sure is a spiffy litte function.

I'm just going to return the focus to the first box. I think if I put a detailed enough msgbox then my users will see what they fat fingered in eitheir box.

You ROCK!

thanks brotha!!
 
I'm so close to the finish line but I've stumbled... Ideally I would like the input validation to be fired off once the user clicks a submit button. Now it kicks off anytime I tab to the next box to enter a vlaue.

What is the fix oh mighty access gods???
 
Did you use the form's before update event, or the textbox's? The form's shouldn't fire until the end.
 
That solved half of my problem. I was using the boxes update event. Now when I enter bad values it runs the code I have in the onClick event of the button before the form before update check. Is there any way to switch that around so it first checks the value???
 
What is the click event doing? I assume it's doing something and then closing the form, which is when the update code runs. You can't change that order. Hard to say without knowing the situation, but perhaps you may want a function that does the testing and returns a boolean. You could then call that function from anywhere, in this situation perhaps both the button and the before update event. You could just do your testing in the button's code, but then it doesn't run if they close down the form without clicking your button.
 
The click event parses the data into a "/" seperated string. I would have done the input validation in the onClick form the beginning if I knew how to. I don't know how to stop executing the code and return the focus back to a textbox if the data is invalid.

You've been very helpfull thus far Baldy, I appreciate your efforts and I've used your site as a reference when dealing with some other problems I've had.

Thanks,
 
Borrowing this from my site, your code in the click event would be:

Code:
If Len(Me.SomeControl & vbNullString) = 0 Then
  MsgBox "You need to fill out SomeControl"
  Me.SomeControl.SetFocus
  Exit Sub
End If

As I mentioned, the downside to doing it there is that the user might be able to get around it.
 
For some reason it's just closing the form when I do this...

Code:
''input validation for  dates
If Me.BeginDate.Value >= Me.EndDate.Value Then
MsgBox ("Begin Date must be before end date")
Me.BeginDate.SetFocus
Exit Sub
End If
 
Do you get the message box?
 
Then the exit sub line should kick it out of the code before it gets to the line that closes the form. No error or anything? Can you post the db?
 
Baldy my man...

I got it working!!! I didn't even have to use the beforeupdate(). I just did some elseifs to validate the input. Here's my code.

Thanks again for helping me work through this tricky little issue.

This is what worked for me:
Code:
Private Sub Command4_Click()
If IsNull(BeginDate.Value) Then
    MsgBox ("Please enter the begin date.")
    BeginDate.SetFocus
    Exit Sub
    
ElseIf IsNull(EndDate.Value) Then
    MsgBox ("Please enter the end date.")
    EndDate.SetFocus
    Exit Sub
    
ElseIf BeginDate.Value > EndDate.Value Then
    MsgBox ("Begin Date occurs after end date, please revise.")
    BeginDate.SetFocus
    Exit Sub
ElseIf Len(BeginDate) <> 8 Then
    MsgBox ("Begin Date must be following format: YYYYMMDD")
    Exit Sub
    
ElseIf Len(EndDate) <> 8 Then
    MsgBox ("End Date must be following format: YYYYMMDD")
    Exit Sub
    
Else
    Me.Visible = False

Dim strDate, EDate As Date
Dim x, y As String
x = Me.BeginDate.Value
y = Me.EndDate.Value
x = x + "010101"
y = y + "231212"
strDate = Get_Date_Time(x)
EDate = Get_Date_Time(y)
Me.Label6.Value = strDate
Me.Label7.Value = EndDate
DoCmd.SetWarnings (False)
DoCmd.OpenQuery "qry_Lost_Revenue"
DoCmd.SetWarnings (True)
Call Fix_Revenue_Temp_Table
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom