Do I need VBA?

  • Thread starter Thread starter Vincent
  • Start date Start date
V

Vincent

Hi,

I have two related tables linked by and InvoiceID as the
primary key for one table and a foreign key for the other
table.

I have made a form and subform. I set both keys to be
required.

My PROBLEM is I noticed that users can fill in all
required fields for the first Main form but can choose to
close the application and allows it to save information on
main form.....

How can I make it so that the Main form ONLY saves if the
requirments in the Subform (Required fields) are all
filled?

Currently it allows a record to be saved with no subform
detail, thus useless record. Please help I suck at VBA.

Thanks!!!!!

..
 
Yes, you need VBA.

You would need to add some code to the "On Exit" Event of
the subform.

There is a way to select, delete, append, and update
records based on criteria using VBA.

That is what you need to do.
You need to delete the record on the main form if the
subforms record count is null or = 0.
If RecordCount = 0 Then
DoCmd.RunSQL "Delete * " & _
"From tblName" & _
"Where ((tblName.ID)=Forms!frmMain!ID)"
Else:
End If

The above code is only an example.
You need to study.
To give you the exact way to do what you want would take
more time than i have.

I hope i have helped. Good Luck!
 
Back
Top