Number field

C

Carol Shu

how to do this...
there are 2 number fields in my form, how to set up that "field B" number
must be greater or equal than "field A", ex: if "field B" is 11111, then
"Field A" must be 11111 or 11110, many thanks.
 
J

Jeanette Cunningham

Carol,
You can use the before update event of the control for field B.
Assuming Long Integer

------------------
If Me.BControlName.text <= Me.AControlName Then
Cancel = True
MsgBox "Invalid number"
End If
------------------

If using single or double you may need to use the format function to format
them so they both have the same number of decimal places in the code above.
example: Format(Me.BControlName.text), "#0.00") in place of
Me.BControlName.text

Replace the obvious with your field and control names.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
J

John W. Vinson/MVP

how to do this...
there are 2 number fields in my form, how to set up that "field B" number
must be greater or equal than "field A", ex: if "field B" is 11111, then
"Field A" must be 11111 or 11110, many thanks.

First off... forms don't have fields.

TABLES have fields, and tables, and only tables, store data. A Form is
just a window to edit data in Tables.

You can set a Table Validation Rule in your table to prevent addition
of a record with FieldB less than FieldA; or you can use VBA code in
the Form's BeforeUpdate event to check as well. The latter may be a
bit more friendly to the user since you can control how the error
message is presented. for example, you could view the Form's
properties; click the ... icon by the BeforeUpdate event on the Events
tab; and edit the code to something like

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me!FieldB < Me!FieldA Then
MsgBox "Please be sure FieldB is greater than or equal to FieldA", _
vbOKOnly
Cancel = True ' cancel editing the record
Me!FieldB.SetFocus
End If
End Sub
 
C

Carol Shu

Hi,
You're absolutely right about the Fields,
and i'd like to thank you for helping me, it work perfect.
 
Top