Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ms access 2000 data validation 1

Status
Not open for further replies.

thepope77

Technical User
Jul 1, 2003
26
US
Hi:
I need to perform data validation on an AfterUpdate Event. I am validating a dimension- a tolerance. I need to specify a range of which the data can be. Like, between 0.172 and 0.174, for example.

The data to be validated is in a text box. But the criteria for what the range needs to be depends on what is selected in a combo box on the same form. For example:

If cboWireSize=0.172 Then
txtActualWireSize >=0.172 or <=0.174
Else MsgBox &quot;The wire is out of spec.&quot;
End If

Pardon any inconsistencies. I am a newbie to this game.
Any help is greatly appreciated. Thanks a lot.

Daniel Pope
 
Hi thepope77,

You should normally do validation in a BeforeUpdate event - AfterUpdate is too late. Apart from that, what is your problem / question?

Enjoy,
Tony
 
Hi Tony:

I guess the BeforeUpdate is a better choice for this. Like I said, I am a newbie. I know just enough code to be dangerous.

My problem is that I am not exactly sure how to write the code to validate these data as there are about 10 different wire sizes. Will I have to declare variables in the procedure or can I simply do the validation on the text box?

I appreciate any help and thanks for bearing with me and my newness.

Daniel
 
Hi Daniel,

Based on what you have posted so far here is some code you can start with. I've made up the values as you will see; other than that it should be OK.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Low As Double, High As Double

If IsNull(Me.cboWireSize) Then
    MsgBox &quot;Please select one of the choices in the combo&quot;
    Cancel = True
    Me.cboWireSize.SetFocus
    Exit Sub
End If

If IsNull(Me.txtActualWireSize) Then
    MsgBox &quot;Please enter a value&quot;
    Cancel = True
    Me.txtActualWireSize.SetFocus
    Exit Sub
End If

Select Case Me.cboWireSize
    Case &quot;Hairline&quot;:  Low = 0.001:  High = 0.002
    Case &quot;Thin&quot;:      Low = 0.01:   High = 0.02
    Case &quot;Medium&quot;:    Low = 0.1:    High = 0.2
    Case &quot;Thick&quot;:     Low = 1:      High = 2
    Case Else
        MsgBox &quot;Please contact the Help desk&quot;
        Cancel = True
        Me.Undo
        Exit Sub
End Select

If Me.txtActualWireSize < Low Or Me.txtActualWireSize > High Then
    MsgBox &quot;The wire is out of spec.&quot;
    Cancel = True
    Me.txtActualWireSize.SetFocus
End If

End Sub

Enjoy,
Tony
 
Thanks a lot Tony. That really helped. Even I can get that to work without any problem.

I did try this on a form that contains a subform but the data in the subform doesn't show up until the AfterUpdate event. Do you know what might be causing that? This is not a major issue so you don't have to respond. Just curious. You have helped me out immensely already.

Thanks much again. Hopefully, soon, I can give a little back rather than just taking.

Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top