Subform defaults

  • Thread starter Thread starter knobblysnail
  • Start date Start date
K

knobblysnail

Guest
I have a form containing 2 nested subforms. Usually the controls on the first subform are not changed from the default values.

On the parent form I have a New Record button which fires the automatically created code:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.GoToRecord , , acNewRec

This New Record button saves the data on the parent form, but does not create records for the subforms. They are all saved correctly if I use the navigation buttons on the main form to move to a new record.

How do I get my own button to work properly?

Is there a way to save default values on a subform without making any changes?

thanks
 
2 Questions.

Why are you saving the record via code as when you move to a new record, the changes made are committed to the record anyway. (And there is more efficient code than that menubar stuff)

but does not create records for the subforms
What records do you want creating for the subform?

If you move to a new record on the parent form, then (if your master and child links are correct) you will also have a new record on all subforms also. Can you clarify?
 
as Fizzio has pointed out, you need to explain further exactly, what you are trying to do.

as regards this line of code

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

you should replace it with

Code:
DoCmd.RunCommand acCmdSaveRecord
 
Further details

Thanks for your advice maxmangion and Fizzio. I was unaware of the RunCommand method.

As for further details about the form, it is based on 3 tables tblPatient, tblOperation and tblProcedure, with primary keys respectively PatientID, OperationID and ProcedureID. tblPatient!PatientID has a one-to-many relationship with tblOperation!PatientID and tblOperation!OperationID has a one-to-many relationship with tblProcedure!OperationID. The tables and relationships are in a linked database.

The main form, frmPatient, is based on tblPatient and contains a subform based on tblOperation, sfrOperation. In turn nested within sfrOperation is sfrProcedure. While frmPatient and sfrOperation are in form view, sfrProcedure is a continuous form. The first 2 are linked on PatientID as master and child fields and similarly the last 2 are linked on OperationID.

While each patient has a different combination of procedures, the operation details such as date, hospital etc are predictable and thus are the defaults shown. This means data is often only actively added to frmPatient and sfrProcedure.

When I click on my New Record button on frmPatient, only the frmPatient data is stored - not the data in either subform unless I either 1) go back to the patient record and re-enter the procedure, 2)Specifically save the data with Shift-Enter or 3) use the record navigation buttons on frmPatient. Fizzio this is why I tried explicitly saving the record in code - however as it is not saving the subforms you are quite right to state it is redundant.

My reason for having a user defined button for the new record is to provide a keyboard shortcut to make a new record explicitly on tblPatient.

Many thanks
 
I think I follow.

You have set default values for your operation and therefore are only adding data to the patient and procedure forms? These will only be committed if you actually enter the operation record and start typing.

If your relationships are set correctly, this should not be possible as the correct data entry would be Patient, Operation, Procedure - you seem to be shipping the Operation bit.

Initially check your relationships so that you cannot miss a step and if you really want to cut corners, use a button on the procedures form to add a record programatically to the form with the default values you specify (you could hold these in a remote table if you wanted)

If you are still stuck, get back (or even better post a knock down version for us to play with :cool: )
 

Users who are viewing this thread

Back
Top Bottom