Avatar of smiths87
smiths87Flag for United States of America

asked on 

Access Subform is not acting like the form it is based on (on open macros, etc.)

I have a form we'll call "Form A" that when opened runs a macro which sets a combo box on the form to a certain value.  This works fine when "Form A" is openend, and "Form A" does not display the parameters box since it is getting the value from the code in it's On Open event.  Then I created a new form that has "Form A" as a subform, and when I open this new form it asks for Parameters, etc., that are covered in the On Open macros of "Form A".  I can't figure out why exactly or how to fix it.  It is as if the new forms opening does not engage "Form A"'s code.  Looking for a way to make sense of it.  Thanks.
Microsoft Access

Avatar of undefined
Last Comment
Jeffrey Coachman
Avatar of harfang
harfang
Flag of Switzerland image

Could you post the form's On Open event code, its record source, and the names of the parameters you get prompted for?

(°v°)
ASKER CERTIFIED SOLUTION
Avatar of dqmq
dqmq
Flag of United States of America 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 dqmq
dqmq
Flag of United States of America image

PS.  Look at the RecordSource of the form in question.  I expect it references a combobox control on your form.  That's what you need to change.
Avatar of dqmq
dqmq
Flag of United States of America image

I'm afraid I was not clear.  Look for something like this in the RecordSource of your form:

  Forms![Form A]![YourComboBox]

And change it to something like this:
   Forms![Main Form]![Subform Control]!Form![YourComboBox]
Avatar of smiths87
smiths87
Flag of United States of America image

ASKER

harfang:  The On_Open code is very simple.  It sets "Form A" 's cboPeriodcopy combo box value to 5, and requeries.  I assumed that when the Main Form opens with the subform (which is "Form A"), it would do all of the On_Open, etc. that is written for "Form A".  

Regardless of what I've tried with dqmq's suggestions and others I've seen I get the below:
Forms!FormA!cboPeriodcopy  - Parameter box everythime I open the subform, apparently every way I've tried to set it to anything isn't doing it.

Thanks for the suggestions, any more ideas pop up feel free to let me know and I'll try them out.
SOLUTION
Avatar of harfang
harfang
Flag of Switzerland 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.
Avatar of Jeffrey Coachman
smiths87,

<The On_Open code is very simple. >
So simple that you forgot to post it?
;-)

Since you did not post any details on:
How *exactly* this value is set (via VBA or actually by an actual "Macro")
...In either case you will get a warning about the event not running, (not a parameter prompt)
How this value is determined
Whether "Form A" is bound or not
The relevant property settings of the combobox
The details of the new Main form
The specific "Parameter" it is prompting you for
The ultimate purpose for needing to do this
...etc.

It is difficult to tell...
When I replicated your setup:
I got a VBA error when I use code to set the combobox
I got a Macro error when I use a macro to set the combobox value.

I never get a parameter prompt.
So again, it seems as though there is something else at play here.
(or perhaps I am misunderstanding something...)

So can you can either lift the veil of secrecy for my above concerns?, ...or post a sample DB, so that minimal guesswork is required to assist you.

In any event, ...a parameter prompt is what you get when Access does not recognize a field.
(...so it prompts you for the value.)  
So you may have miss-spelled something when you created the new main form.
So double check your spelling for all of the relevant objects.

;-)

JeffCoachman

Avatar of smiths87
smiths87
Flag of United States of America image

ASKER

Ok figured it out.  "Form A" 's record source was "Query A", and "Query A" had a parameter for the cboPeriodcopy on "Form A".  I changed that parameter in "Query A" to the below to reference the "Form A" subform as opposed to the original stand-alone "Form A".

[Forms]![FormB]![SubformA].[Form]![cboPeriodcopy]  (Example from harfanq's 2nd comment)

Basically I just glossed over the fact that "Query A" was really what I was needing to get at, like dqmq was hinting at, not "Form A".  Cheers to everyone, all three posters had me delving into various little aspects that have given a little better understanding of the issues involved.  Now I can really foul things up.

Boaq2000 - since you took the time to reply I figured I'd answer your questions just as an FYI with my thanks:

My very simple On_Open code in VBA for "FormB" (the Main Form with the sub in it):
Forms![Form1]![Sales].Form![cboPeriodcopy] = 1

The Value used is arbitrary, could be whatever I choose from 1 through 13 (relating to periods in a year - which is what cboPeriodcopy contains).

"Form A" was bound to "Query A"  (hence part of my problem that I didn't realize)

The Main Form I am just putting together as an easier way to view several different forms on a multi-tabbed form.  I had already built "Form A" and the like, but decided a multitabbed was easier on the user as far as jumping around.  Just had that little hang up with not realizing some of the inner workings.  And the specific parameter it was asking for was that "Query A" parameter that was set to "Form A" 's combo box, not the subform's combobox, which I've now remedied.  
Avatar of harfang
harfang
Flag of Switzerland image

Thanks for the detailed feedback, and success with your project! — (°v°)
;-)
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