I have a form and a subform. I would like to create a one-to-many relationship, however when I create a new record within the main form, my subform won't allow new data to be entered. I have attached my sample database (in access 2007).
To see the problem, simply click the "new treatment" button and try to enter some new data into the subform.
If you open your subform directly, can you then add new records?
In most cases, this behavior is due to (a) invalid, non-updateable query on the subform or (b) invalid Master/Child links between the Main and Subform. This can also be the result of improper table structures (i.e. if you haven't correctly structured the Parent/Child relationship between the tables driving the Main/Child form).
The query that you have for your main is far too complex for the job and as a result will not allow addition of records. You have a relationship between tbl_treatment and tbl_subformtreatment that just shouldn't be there (it can't add a treatment until there's a matching entry in the subformtreatment table, which can't be entered until the treatment is added ...)
Just drop tbl_Subformtreatment from your form's query and you'll be able to add records. To get data from tbl_Subformtreatment to use in calculations on the main form use DLookUp()
You also don't need tbl_Patients in your form's query:
- make the source of your patient selection combo:
SELECT ([tpfirstname]) & " " & ([tpsurname]) as Patient, tbl_Patients.tpPatient FROM tbl_Patients ORDER BY tbl_Patients.tpFirstname;
- Set the Bound column = 2
- Set the column count to one
- make the combo big enough to display the name
- delete the text box Text45
>Just drop tbl_Subformtreatment from your form's query and you'll be able to add records.
I removed tbl_subformtreatment from qry_treatments (the main form's query), however I'm still not able to add records to the subform. The error message I'm getting is:
"You can't assign a value to this object
*The object may be a control on a read only form
*The object may be on a form that is open in design view
*The value may be too large for this field"
(You should be able to see this message yourself when you view my sample database).
We were facing a similar issue when a client approached us with the problem that they could not create new child record in a subform in a situation where there were not **already any exsiting child records** for the master record. The solution was to set the correct "Trust Centre Settings" in Access 2007 - this may also be worth checking in addition to the points above.
Microsoft Access
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.
In most cases, this behavior is due to (a) invalid, non-updateable query on the subform or (b) invalid Master/Child links between the Main and Subform. This can also be the result of improper table structures (i.e. if you haven't correctly structured the Parent/Child relationship between the tables driving the Main/Child form).