Avatar of Dozingquinn
DozingquinnFlag for Australia

asked on 

Subform won't create new record (Access 2007)

Hello,

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.

Could you please tell me how to fix this? Thanks!
Sample-Database.zip
Microsoft Access

Avatar of undefined
Last Comment
mckenzieGregory
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

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).
Avatar of MikeToole
MikeToole
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of Dozingquinn
Dozingquinn
Flag of Australia image

ASKER

Thanks MikeToole,

I tried the following:

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

Am I missing something?
ASKER CERTIFIED SOLUTION
Avatar of MikeToole
MikeToole
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Dozingquinn
Dozingquinn
Flag of Australia image

ASKER

Thanks for taking the time to go into so much detail it was a great help. You're a legend.
Avatar of mckenzieGregory
mckenzieGregory

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

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.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo