Form validation and deleting record if dirty

  • Thread starter Thread starter Jan T.
  • Start date Start date
J

Jan T.

Hi!
I have a form "Return_Material_Authorization" that generates a consecutive
RMA number and saves it to the RMA table. That assures that if another user
creates anRMA the RMA number is unique.
If a user does not fill the form or decides to exit without filling at least
4 fields (Customer_ID, Customer_Name, Customer_PO and Part_Number) I want the
record deleted so that all records are valid.
Here is a snippet of the code I use in BeforeInsert event of the form:

Private Sub Form_BeforeInsert(Cancel As Integer)
'Find next R_ Number
Me![RA_Number] = Format(DMax("[RA_Number]",
"[Return_Material_Authorization]") + 1, "00000")

'Write the record to disk immediately
Me.Dirty = False
End Sub
 
Hi!
I have a form "Return_Material_Authorization" that generates a consecutive
RMA number and saves it to the RMA table. That assures that if another user
creates anRMA the RMA number is unique.
If a user does not fill the form or decides to exit without filling at least
4 fields (Customer_ID, Customer_Name, Customer_PO and Part_Number) I wantthe
record deleted so that all records are valid.
Here is a snippet of the code I use in BeforeInsert event of the form:

Private Sub Form_BeforeInsert(Cancel As Integer)
'Find next R_ Number
    Me![RA_Number] = Format(DMax("[RA_Number]",
"[Return_Material_Authorization]") + 1, "00000")

'Write the record to disk immediately
    Me.Dirty = False
End Sub

make all 4 of the fields required. Then if the fields aren't filled
in, the record cannot be saved if the fields aren't filled in.
 
I chaned all 4 fields to Required.
When I start entering Customer_ID I am getting VB Run-Time error '3314' "The
field "Return_Material_Authorization.Customer_ID' cannot contain a Null value
because the Required property for this field is set to True. Enter a value in
this field"

When klicking a "Debug" button VB highlights
Me.Dirty = False

Jan T.


Piet Linden said:
Hi!
I have a form "Return_Material_Authorization" that generates a consecutive
RMA number and saves it to the RMA table. That assures that if another user
creates anRMA the RMA number is unique.
If a user does not fill the form or decides to exit without filling at least
4 fields (Customer_ID, Customer_Name, Customer_PO and Part_Number) I want the
record deleted so that all records are valid.
Here is a snippet of the code I use in BeforeInsert event of the form:

Private Sub Form_BeforeInsert(Cancel As Integer)
'Find next R_ Number
Me![RA_Number] = Format(DMax("[RA_Number]",
"[Return_Material_Authorization]") + 1, "00000")

'Write the record to disk immediately
Me.Dirty = False
End Sub

make all 4 of the fields required. Then if the fields aren't filled
in, the record cannot be saved if the fields aren't filled in.
 
Back
Top