Show form and subform in creation mode with VBA (1 Viewer)

Superpat

Member
Local time
Today, 21:56
Joined
Aug 15, 2020
Messages
103
Hello,
It's a strange question, I can easily do it another way, but I'm curious and want to know if it's possible to do it my way.
When I type in execution mode :
Code:
DoCmd.OpenForm "_f_Principal", acDesign
Or, when in a module, I have :
Code:
Sub commande3()
DoCmd.OpenForm "_f_Principal", acDesign
End Sub
and I click <F5>
Or, when I right-click on the closed form and choose Design mode, the form and all its sub-forms open.
-------
I've created a button on the form (which I leave on the last or penultimate line)
Code:
Private Sub cmdCreation_Click()
          DoCmd.Close acForm, "_f_Principal", acSaveYes
          'DoCmd.OpenForm "_f_Principal", acDesign
         commande3
End Sub
And there the form opens, but not the sub-form !
It is possible to do it ?
It
2024-07-01_202333.jpg
 

Attachments

  • 2024-07-02_091847.jpg
    2024-07-02_091847.jpg
    142.1 KB · Views: 8
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 12:56
Joined
Oct 29, 2018
Messages
21,699
Can you post a screenshot of the form in design view when you do it normally?
 

isladogs

MVP / VIP
Local time
Today, 20:56
Joined
Jan 14, 2017
Messages
18,330
The screenshot suggests your subform is already open elsewhere. As a result, it can't be opened again.
Close it and try again

BTW I strongly recommend you do not start object names with an underscore.
 

Superpat

Member
Local time
Today, 21:56
Joined
Aug 15, 2020
Messages
103
The screenshot suggests your subform is already open elsewhere. As a result, it can't be opened again.
Close it and try again

BTW I strongly recommend you do not start object names with an underscore.
Sorry for underscore, but it's too late ...
Oops, I forgot to say the main thing, it came back to me this morning : it's the tab control that won't open.
I am attaching a similar file, the form to be opened is "frm_PiecesAccessoires" and the button is called Design
 

Attachments

  • Database3.accdb
    1.8 MB · Views: 16

isladogs

MVP / VIP
Local time
Today, 20:56
Joined
Jan 14, 2017
Messages
18,330
Sorry for underscore, but it's too late ...
The forms in your example don't have leading underscores!

When I open the form it asks for a parameter value twice. No idea what to enter there!
If I click past that dialog, the form opens including the tab control.
However, the form looks nothing like your screenshot from post #1

1719919041212.png
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:56
Joined
Sep 21, 2011
Messages
14,746
And if you click the Design button it opens the form in design mode? after closing the form?

Not a brilliant idea in my view TBH. All the design should be done before hand, not handed to users.
 

Superpat

Member
Local time
Today, 21:56
Joined
Aug 15, 2020
Messages
103
The forms in your example don't have leading underscores!

When I open the form it asks for a parameter value twice. No idea what to enter there!
If I click past that dialog, the form opens including the tab control.
However, the form looks nothing like your screenshot from post #1
I've made a light example of the first post, without underscore. Now you have to click on button Design.
With Button Design :

Design_01.jpg


With Mode Design or Module1. That's what I'd like to do

Design_02.jpg
 

isladogs

MVP / VIP
Local time
Today, 20:56
Joined
Jan 14, 2017
Messages
18,330
If you open the form in design view directly from the navigation pane, you will see the subform design as well
Similarly if you change to Design view from either the right click context menu or the View menu on the ribbon

For reasons that I haven't investigated, the ribbon View menu is disabled when any of your 3 forms are opened

Anyway, I agree with @Gasman. Users should never go into Design view
If you really must do this from a button then you should only need one line of code

Code:
Private Sub cmd_Design_Click()
    DoCmd.OpenForm "frm_PiecesAccessoires", acDesign
End Sub

However, that will only work as you want on the first occasion. Personally I'd scrap the idea and go to Design view another way.
 

Superpat

Member
Local time
Today, 21:56
Joined
Aug 15, 2020
Messages
103
Thank you both for your answers. I only have one user : myself, but that's enough to cause me problems.
I wanted to put the form and the sub-form (that is in the tab control) into design mode, but the subform never gets completely set with my Design command (See post 9 with the red arrow).
Code:
Private Sub cmd_Design_Click()
    DoCmd.OpenForm "frm_PiecesAccessoires", acDesign
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:56
Joined
Sep 21, 2011
Messages
14,746
Yes, I see what you mean, but no idea how to fix it. opening the subform in design mode opens it as a separate form?
Seriously, I would just right click any form I want to work on.
 

Superpat

Member
Local time
Today, 21:56
Joined
Aug 15, 2020
Messages
103
Yes, I see what you mean, but no idea how to fix it. opening the subform in design mode opens it as a separate form?
Seriously, I would just right click any form I want to work on.
Yes, I said that in my first post. But you never know...
Or, when I right-click on the closed form and choose Design mode, the form and all its sub-forms open.
Thanks again for your answers.
 

Josef P.

Well-known member
Local time
Today, 21:56
Joined
Feb 2, 2023
Messages
921
Code:
Private Sub cmd_Design_Click()
    Me.Accessoires_sous_formulaire.SourceObject = vbNullString  ' <-- unload subform
    DoCmd.Close acForm, "frm_PiecesAccessoires", acSaveYes
    Commande3
End Sub
... or use another form so that the form to be opened can close completely before opening.
 

Attachments

  • Database3.zip
    92 KB · Views: 5
Last edited:

Users who are viewing this thread

Top Bottom