Form validation and deleting record if dirty

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
 
P

Piet Linden

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.
 
J

Jan T.

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.
 

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

Top