Validate textbox prior to entry

Z

Zack Barresse

Hello everyone,

I have a form that was created by the wizard (not very Access-savvy here). I have a textbox that takes a value for a specific item (Conductivity for a water sample). I need some validation on this textbox when the Next Record button is pushed. It should be anywhere from 2 - 15 (as Double). If the user enters the number as a different log (i.e. 200 - 1500) I need it input into the record as 2 - 15. For example, here are some entries and what their value should be in the table/recordset:

Value Entry
215 2.15
10.55 10.55
1167 11.67
1481 14.81
15.27 15.27

Does this make sense? If more info is needed, let me know.
 
A

Allen Browne

Use the AfterUpdate event of the text box to divide by 100 if it is too
large.

Example:

Private Sub Conductivity_AfterUpdate()
With Me.Conductivity
If IsNull(.Value) Or (.Value >= 2 And .Value <= 15) Then
'do nothing
Else
If .Value >= 200 And .Value <= 1500 Then
.Value = .Value / 100
Else
MsgBox "Conductivity must be between 2 and 15."
.Value = Null
End If
End If
End With
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Hello everyone,

I have a form that was created by the wizard (not very Access-savvy here).
I have a textbox that takes a value for a specific item (Conductivity for a
water sample). I need some validation on this textbox when the Next Record
button is pushed. It should be anywhere from 2 - 15 (as Double). If the
user enters the number as a different log (i.e. 200 - 1500) I need it input
into the record as 2 - 15. For example, here are some entries and what
their value should be in the table/recordset:

Value Entry
215 2.15
10.55 10.55
1167 11.67
1481 14.81
15.27 15.27

Does this make sense? If more info is needed, let me know.
 
Z

Zack Barresse

Allen, that worked beautifully! Glad it was simple like that. I just need
to study the Object Model a little more. Excel is very easy for me, but
Access is new. Much appreciated you showing me the way here. :)
 
Top