Number field

  • Thread starter Thread starter Carol Shu
  • Start date Start date
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.
 
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
 
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
 
Hi,
You're absolutely right about the Fields,
and i'd like to thank you for helping me, it work perfect.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top