Avatar of beatified
beatifiedFlag for United States of America

asked on 

Errors in Access forms and subforms.

I am getting two errors.

First one is when I click the "New Tenant" button on the bottom of the "frmNewLease"

The second is when I select a Make in the Vehicle form. This seems to work fine when I bring up the form independently but not when I bring it up as a subform.

See the attached Screenshots and DB

I am also unsure that the Vehicle form is properly connected to the Tenant which is its parent form.

Thanks,
Stuart
HCPV-Current.accdb
New-Tenant-Button.jpg
Make-Select-Error.jpg
Microsoft Access

Avatar of undefined
Last Comment
PatHartman
Avatar of PatHartman
PatHartman
Flag of United States of America image

To refer to a subform on a form, you must include the main form

Forms!mainform!subform!control
ASKER CERTIFIED SOLUTION
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France 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 beatified
beatified
Flag of United States of America image

ASKER

Thank you both for the answers.
@PatHartman
I am trying to learn how to do this but don't seem to be having much luck. I even tried the subform wizard and I figured it would be sufficient. The problem is that It seems the other errors are getting in the way of checking to see if it is working.

@Fabrice Lambert
I found that I had an error in the relationships but now that it is fixed the frmVehicle form works as expected but that same form as a subform doesn't work. Any idea as to why? I know you said that I was trying to execute a query with the same name as the comboBox but wouldn't that mean that the form on its own would have the same error? Right now it doesn't.

And thanks for the requery fix it worked like a charm.

I've attached a new copy of the DB to reflect the relationship change and BTW was under tblCarModel.
HCPV-Current.accdb
Avatar of PatHartman
PatHartman
Flag of United States of America image

If the form works as a main form but not as a subform, you have some reference that is incorrect and you need to find it.  "doesn't work" is not helpful.  What is the error message you are getting and can you identify the line of code that is causing it?  When the error message pops up, use cntl-break to drop into the code.  If you drop into an error routine, you need to add a line of code after your module exit-

Resume

Then move the focus to the Resume statement using the yellow right arrow from the debug menu.  Click on the line you want to be active and then click on the yellow right arrow.  The line with the focus should highlight.  Then you can step through the code and focus should move to the line that actually caused the error.

As long as the Resume is after an Exit Sub or Resume Next, it will never be executed.  It is only there  for you to use for debugging.
Avatar of beatified
beatified
Flag of United States of America image

ASKER

@PatHartman
I am not receiving an error at this point. I am just getting something asking for criteria for a requery. Everything seems to work fine when the the form is loaded independantly but but doesn't work when the form is a subform. The form I am referring to is frmVehicle.
Avatar of PatHartman
PatHartman
Flag of United States of America image

There is an issue with how you are referencing the form.  As I mentioned originally, you MUST include the mainform name in front of the subform name.  Look again at my example.
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