Need Subform to open in a Subform window... (1 Viewer)

bmhuettinger

Registered User.
Local time
Today, 05:57
Joined
Jul 28, 2017
Messages
59
Good afternoon all!
The following code works exactly as I need it to - by double clicking a master form, I can open and populate fields on a child form. The problem is that the code is telling the form to open in a new window, and I'd like to just open in the subform window (I don't want to see the subform until I open it). A visible=true event doesn't help me.

Private Sub TagNumber_DblClick(Cancel As Integer)
DoCmd.OpenForm "frm_IPOAllocationWorksheet", acNormal
DoCmd.GoToRecord , , acNewRec
Forms!frm_IPOAllocationWorksheet.TagNumber = Me.TagNumber
Forms!frm_IPOAllocationWorksheet.Net = Me.Net
Forms!frm_IPOAllocationWorksheet.IPONumber.SetFocus
End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:57
Joined
Aug 30, 2003
Messages
36,131
Why doesn't setting visible = true help you? If the subform exists on the form but is hidden, that's the way to make it visible. OpenForm is going to do exactly that, open a form. Another alternative is setting the source object property of a subform control.
 

bmhuettinger

Registered User.
Local time
Today, 05:57
Joined
Jul 28, 2017
Messages
59
Thanks for the reply!
Are you suggesting that I change the DoCmd.OpenForm part of my code to visible=true? It's not working for me so I think I'm missing something. Would it possible for you to show me which part of my code needs to be modified?

Private Sub TagNumber_DblClick(Cancel As Integer)
DoCmd.OpenForm "frm_IPOAllocationWorksheet", acNormal
DoCmd.GoToRecord , , acNewRec
Forms!frm_IPOAllocationWorksheet.TagNumber = Me.TagNumber
Forms!frm_IPOAllocationWorksheet.Net = Me.Net
Forms!frm_IPOAllocationWorksheet.IPONumber.SetFocus
End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:57
Joined
Aug 30, 2003
Messages
36,131
Yes, presuming the subform exists and is not visible to start.

Me.SubformControlName.Visible = True
 

bmhuettinger

Registered User.
Local time
Today, 05:57
Joined
Jul 28, 2017
Messages
59
ok - the problem that I have is that when I replace the OpenForm command with visible=true, I get an error message that says "you can't go to the specified record".
If I switch the code back to OpenForm, it works again.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:57
Joined
Feb 19, 2002
Messages
43,196
You have to place one form on the other. When you do it by dragging, Access names the subform control with the same name as the form object you dragged onto the main form. Most people name their forms using "frm" as a prefix and subforms using "sfrm" as the prefix. It helps if you make your own navigation forms. your query would only select forms that start with "frm" and ignore everything else.

Once the subform is an object on another form, then the Me.sfrmSomeName.Visible = True will work. Remember you are reference the subform CONTROL, not the subform object so you must use the Name property in the subform control if it is different from the actual name of the subform object.
 

bmhuettinger

Registered User.
Local time
Today, 05:57
Joined
Jul 28, 2017
Messages
59
Thank you for reply. I'm really not a total novice when it comes to Access but this little subform is causing me a lot of problems. Per your suggestion, I've renamed this form (and all of my subforms) to sfrm_xxxxxx. I deleted the subform entirely, and made sure that it was, in fact, appearing as a subform within my subform, not just floating around on the main form. Two things are happening that I cannot solve.
1. Me.sfrm_IPOAllocationWorksheet.Visible = True, doesn't give me errors but it still seems to be preventing the next line of the code - DoCmd.GoToRecord,,,acNewRec - from working ("cannot go to specific record")
2. even the the subform properties is set to Visible=No, I can still see it.

I'm very frustrated that something that's seemingly so simple is turning out to be so complicated...I have several instances throughout my DB where pop-up subforms work just fine????
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:57
Joined
Jul 9, 2003
Messages
16,269
I'm wondering if there is a bit of confusion over the definition of a subform... In terms of MS Access a sub-form is nothing but an ordinary form. It becomes defined as a subform in the following process. Open a form in design view, let's call this the "main form", the form that's going to carry the subform. Now drag the form you want to become a subform from the list on the left onto your main form. It will be positioned on your "main form" and you now refer to it as a Sub Form! But!... It hasn't really changed, in essence, the only thing that has changed is the dragged in form is surrounded by a special control called a Subform/Subreport Control..

You also mention pop up forms, these are forms which you call by pressing a button on your main form. I'm wondering if you are confusing the two?
 
Last edited:

bmhuettinger

Registered User.
Local time
Today, 05:57
Joined
Jul 28, 2017
Messages
59
I understand that forms become subforms when they are added to mainforms. As I mentioned, my DB is filled with them and I've never had this issue. I also don't think that I'm confused about pop-up forms (but anything is possible) - "my" pop-up forms are forms that are hidden until I double-click certain main form controls and remain visible until I click the pop-up forms and then they disappear. Are these not subforms, too?
I know that a major source of confusion for me comes from calling subforms properly in VBA (I often forget to reference the mainform first before references the subform and, specifically, the subform controls.
I honestly don't believe that is my issue here.
What I'm actually trying to do, is open, and populate a FORM (preferably not as a subform) just not in its own window. Imagine a long, "To Do List" tablet that I'd like to "float" over my mainform for a moment, while I need it, then click it and have it go away until I need it again.
I'm so close but every change that improves one issue, seems to undo a previous solution.
 

mike60smart

Registered User.
Local time
Today, 13:57
Joined
Aug 6, 2017
Messages
1,913
Hi

If you want the subform to go to a new record based on the record you have selected in the Main Form then you are going to have to pupulate the Foreign Key in the Subform using Open Args
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:57
Joined
Jul 9, 2003
Messages
16,269
Well I'm still not getting a clear picture of what you want. I wonder if you could show some pictures?
 

JHB

Have been here a while
Local time
Today, 14:57
Joined
Jun 17, 2012
Messages
7,732
..
1. Me.sfrm_IPOAllocationWorksheet.Visible = True, doesn't give me errors but it still seems to be preventing the next line of the code - DoCmd.GoToRecord,,,acNewRec - from working ("cannot go to specific record")
..
Does the form have the focus?
What happen if you comment out that code line?
Are you able to manually append a new record, when the form open?
Could you post a stripped down version of your database with some sample data + a description how to reproduce the problem you've?
 
Last edited:

Users who are viewing this thread

Top Bottom