vba referring to subform recordsource from module not working...

Arpeggione

Registered User.
Local time
Today, 02:18
Joined
Apr 8, 2008
Messages
18
Hi: I think I am using the code per Bob Larson's (BTAB) wonderful website (his site has helped me immensely) as follows:

Forms!frmEditSystem!subfrmLineswitches.Form.RecordSource = mySQL

this code is setting a recordsource for my subform from a module outside the form. I get the error:

"can't find field subfrmLineswitches"

I'm probably making a careless error? Not sure why this isn't working.

Can anyone help? Thank you!

Arpeggione
 
What's the rest of the code? Is mySQL set in another function, or what?
 
Dim mySQL As String

mySQL = "blah blah"...

I did have this working when I had the procedure in the form_load event and a button, but wanted to put it into an outside module as I am using it in two places...

do you need any more information?
 
Ah, I think I have it. Change the ! to a period:

Forms!frmEditSystem.subfrmLineswitches.Form.RecordSource = mySQL
 
more information....the subform is actually in a container on a tab control on the mainform. the name of the container is TransSubCtnr....

I've got the "syntax for main/subforms" table in front of me.....I'll bet I should be referring to the container instead of the subform?
 
more information....the subform is actually in a container on a tab control on the mainform. the name of the container is TransSubCtnr....

I've got the "syntax for main/subforms" table in front of me.....I'll bet I should be referring to the container instead of the subform?

Yes, that would be the case.
 
well, when I try the dot I get:

application-defined or object-defined error.....
 
You'll still need the dot but you need to refer to the subform control and not the subform itself (if named differently).
 
that's it!

Forms!frmEditSystem!TransSubCtnr.Form.RecordSource = mySQL

it works!

thank you Bob - I tell you these containers are so confusing.....

Karen
 
Glad you got it working for yourself. Subforms always vexed me until I had the explanation from Pat Hartman here on the board. From then on out it was not a mystery anymore. Good luck with the rest of your project. :)
 

Users who are viewing this thread

Back
Top Bottom