Copy a form and make it a popup

mreinsmith

New member
Local time
Yesterday, 22:08
Joined
Nov 25, 2024
Messages
15
I've been wrestling with making a form a popup and opening it

There are many alternatives but I thought I would try copying and renaming a form

Then changing the popup property and opening it

I keep getting can't find object when copying the form

I'm on mobile, I'll post some code when I get back to my desk

I should have waited to post but it's bugging the heck out of me

Matt
 
You'll probably have to check the code behind the form to trace the error.
 
Ok so I was able to copy the form

Code:
    Dim sourceFormName As String
    Dim destinationFormName As String

    sourceFormName = "Frm_Items"
    destinationFormName = "Popup_Items"

    DoCmd.CopyObject , destinationFormName, acForm, sourceFormName
 
    DoCmd.Close acForm, sourceFormName
 
    Dim NewForm As Form
    Set NewForm = Form(destinationFormName)

    NewForm.PopUp = True
 
    DoCmd.OpenForm destinationFormName

Now when I run it I get:

Run-time error '2467:

The expression you entered refers to an object that is closed or
doesn't exist.

on the line "Set NewForm = Form(destinationFormName)"

it was my understanding that you had to close the form to set the popup property
 
I've been wrestling with making a form a popup and opening it
Now that you've shown us your code and we can see the context, all I can say is why? When I read the question, I assumed you had copied the form in design view and were modifying it for use a a popup. I never envisioned doing this on the fly. What are you hoping to accomplish? AND, you will never be able to distribute this application as an .accde or for use with the Access runtime using this code.
 
I'm trying to do the impossible with building an interface...

I'm trying to pop out the forms to display them on another monitor(s)

BTW, I fixed some stuff in the code
 
Every time you modify your code, you need to compile it to check for errors. This assumes you use Option Explicit at the top of every module.
I've got to admit, I never made that a regular practice

I always just relied on compile on demand and the immediate window

Thanks
 
I always just relied on compile on demand and the immediate window
Now is as good a time as any to start applying best practices. Compile before you test - always. Fix compile errors immediately. Save your code frequently. During development, make many backups. I easily end up with a dozen or more for any given day. I don't keep all those backups for very long, usually just a few days but it has saved my bacon on more occasions than I care to remember. You never know when you are going to accidently delete something you've just spent hours perfecting or insert a bug or corruption. If you save frequently as well as C&R, you won't loose more than an hour or so of work. That can still be huge so I always look for good break points where I've got something that I can use as a base to build on.

Also, please tell us why you want to do this "live"? What do you hope to accomplish?
 
Now is as good a time as any to start applying best practices. Compile before you test - always. Fix compile errors immediately. Save your code frequently. During development, make many backups. I easily end up with a dozen or more for any given day. I don't keep all those backups for very long, usually just a few days but it has saved my bacon on more occasions than I care to remember. You never know when you are going to accidently delete something you've just spent hours perfecting or insert a bug or corruption. If you save frequently as well as C&R, you won't loose more than an hour or so of work. That can still be huge so I always look for good break points where I've got something that I can use as a base to build on.

Also, please tell us why you want to do this "live"? What do you hope to accomplish?
Backups, oh yeah! I do my own and in a Pinch pull a previous version from onedrive

I know these things are minutia, but It seemed like such a simple thing to do

I want to be able to pop a tab out to another monitor and I was concerned about when I make changes to a form I would have to make them in both forms

I realize that I can just open a second copy of the database for the other screen but I was concerned about sharing causing it to crash (which in the good old days used to happen all the time)

And so on and so on, and obsession grew. I'm letting it go now because I've killed too much time. Maybe this will help someone else

One good thing came out of it. I fixed a lot of missed declarations using compile. And fixed a bunch of procedures that didn't have option explicit

So thanks much
 
Not sure I understand the intent. However you can open two instances of the same form and you can apply different formatting to each form through code. So you could pop open a second instance and show only a specific tab and hide the other tabs.
see discussion
 
I have forms display as tabbed documents. So I want to "undock" one of the tabs and move it to another monitor

I wish I had thought of saying undock earlier

I've read a lot of posts asking the same question

I thought maybe I had a novel approach
 
I have forms display as tabbed documents. So I want to "undock" one of the tabs and move it to another monitor

I wish I had thought of saying undock earlier

I've read a lot of posts asking the same question

I thought maybe I had a novel approach
To simulate "undocking," I wonder if something like this would work/suffice.
  1. Close the form to remove it from the tabs
  2. Open the form in Dialog mode to make it a popup
However, using dialog mode would mean you'll have to work on that form until you close it. If you intend to keep working with the other tabs while the popup form was moved to another screen, then you cannot use this technique.
 
Not sure if this is what you mean. In the image below there is only one form. The "pop out " is another instance of frmDemo with some tabs hidden and some formatting applied.

PopOut.png

Code to do this is

Code:
Private popOut As Form_frmDemo

Private Sub cmdPop_Click()
  Set popOut = New Form_frmDemo
  popOut.Visible = True
 
  Dim i As Integer
  For i = 0 To Me.tabDemo.Pages.Count - 1
    If i = Me.tabDemo.Value Then
      popOut.tabDemo.Pages(i).Visible = True
    Else
      popOut.tabDemo.Pages(i).Visible = False
    End If
  Next i
  With popOut
    .cmdPop.Visible = False
    .Detail.BackColor = vbBlue
    .Caption = "Pop Out Tab"
    .tabDemo.Style = 2
  End With
End Sub
If you want to be able to update either form and see changes in either form, I would do this with a custom event and a centralized listener. If the pop out is read only then this is easier.
 
You can just use

Set Popout=new frm_employees

Just ensure popup property has been set at design time - it is ignored when form is opened as a subform


Would still need to set some of the popout form properties such as caption and visible. Perhaps also apply any filter criteria to match the subform displayed records
 
You can just use

Set Popout=new frm_employees
My assumption is that the OP wants to see everything on the tab not necessarily a sub form. In fact there may be no subform on the tab or many subforms. The tab could have 3 subforms, it might have no subforms and only data from the main form, it could have a subform with additional labels and formatting.

If the OP simply wants to pop open the subform, then that is simple, but a different question. Just do Docmd.openform.

However in any case it is doable, but not sure if this makes much sense.
 
So you could pop open a second instance and show only a specific tab and hide the other tabs.
@MajP. I believe the OP is not talking about a Tab Control but about Tabbed Documents (versus Overlapping Windows).

You can just use

Set Popout=new frm_employees

Just ensure popup property has been set at design time - it is ignored when form is opened as a subform
@CJ_London. Given the above situation of "undocking" a tabbed document, setting the popup property at design time might not be desirable. If it was set to popup=yes at design time, then it won't show in a tabbed document, which I think is what the OP normally wants. They just want, on certain cases, to undock one of the tabs to move it to another screen.
 
Last edited:
I believe the OP is not talking about a Tab Control but about Tabbed Documents (versus Overlapping Windows).
Oh that makes a lot more sense. I never use tabbed documents so that added to my confusion.
I think then you would have to do what you said. Close then open. Unfortunately I do not think there is a way to have tabbed version and a pop up version at the same time. There is no way to set the pop property at runtime for the second instance.
 

Users who are viewing this thread

Back
Top Bottom