Set SourceObject in VBA (1 Viewer)

jccrvb

Registered User.
Local time
Today, 17:19
Joined
Apr 8, 2009
Messages
10
Hi,
I have two forms: "frm_main" and "frm_sub". "frm_sub" in an unbound sub form on "frm_main". I would like to set the SourceObject of "frm_sub" dynamically in VBA behind a command button on another form. The SourceObject will be one of many forms in the database.
Also on "frm_main", I would like to have 2 buttons with OnClick events that refer to the same SourceObject that is set for "frm_sub".
Hope this makes sense. Basically I want one main form with two command buttons that dynamically will be able to know the name of the source of the sub form which also is dynamically set during an OnClick event on another form (so I don't have 20 forms in the database).
Thanks
 

ezfriend

Registered User.
Local time
Today, 14:19
Joined
Nov 24, 2006
Messages
242
Code:
    Me.sfrmDisplay.SourceObject = "NameOfTheForm"
 

jccrvb

Registered User.
Local time
Today, 17:19
Joined
Apr 8, 2009
Messages
10
I appreciate your reply, but it's a little vague?
"me" usually refers to the current form, right? And is "sfrm" a variable? I want to set the source from another form not itself on open.

In code behind a command button on another form that will open frm_main containing sub form frm_sub, I would like to be able to set the SourceObject of frm_sub. I would also like this same SourceObject name to be available as a string to different command buttons on frm_main after it opens.

Code:
Sub qry_irreg_repo_Click()
Dim myquery As String

' I DO NOT KNOW IF THIS HOW TO REFER TO A QUERY AS A STRING
    myquery = "qry_irreg"

    stDocName = "frm_main"
    
 
'THIS IS WHAT I HAVE BUT IT IS NOT WORKING
    Forms!frm_sub.RecordSource = myquery
    Forms!frm_main!frm_sub.SourceObject = Forms!frm_sub

    DoCmd.OpenForm stDocName, acFormDS
    

End Sub
 

jardiamj

Registered User.
Local time
Today, 14:19
Joined
Apr 15, 2009
Messages
59
I think you can pass the name of the SourceObject to the frm_main when you open it using OpenArgs and then use it in the OnOpen event to set the SourceObject of frm_sub.
I haven try it, so it's just an idea.
If you can't solve it, upload a example of you db.
Cheers!
 

Users who are viewing this thread

Top Bottom