Changing Sub form Source Object?

  • Thread starter Thread starter Tom G.
  • Start date Start date
T

Tom G.

I have a form with a single subform. Based on a login
validation I want to change the source for the subform so
that one of three subforms show depending on the login
type. The main form will open with a default subform
showing. After login I want to switch to one of the other
two subforms. There are no linked fields between the
parent and child forms so I'm thinking it should be a
matter changing the source object and maybe refreshing the
view.

I have all my VBA code written and working for the login
but I can't get the subform to change. Any suggestions on
the proper line of code to do this?

Thanks...
Tom G.
 
Me!NameOfSubformControl.SourceObject = "NameOfSubform"

Note - the quotes are required!
 
Thanks! That did it I put the code in an if then else
statement and the subform toggles as needed.

Funny though, not sure what syntax difference is needed
but when I placed in in the Forms open event to select a
default sub form it bombs out???

Again, Thanks!
Tom G.
 
Subforms always open before the main form so Access needs to know what subform
to open before the OnOpen event of the main form. That's why it bombs out.

Steve
PC Datasheet
 
You could put the code in the forms load event, which occurs after the
Open event.

I've got a form in one of my applications that had 5 different
sub-forms on different tabs. I found that it was taking too long to
load this nightmare every time I moved to a new record, so I modified
it to only contain a single sub-form and just change the SourceObject
as the user moves from tab to tab.

--
HTH

Dale Fye


Thanks! That did it I put the code in an if then else
statement and the subform toggles as needed.

Funny though, not sure what syntax difference is needed
but when I placed in in the Forms open event to select a
default sub form it bombs out???

Again, Thanks!
Tom G.
 
Back
Top