We help IT Professionals succeed at work.

Open a form in another database problem

gbnorton
gbnorton asked
on
I use this code to open a form in another database:

Private Sub btnOpenPlatinumTraveler_Click()
    Dim objACC As New Access.Application
   
    Set objACC = GetObject("T:\Diode Travelers Application\Source\DiodePlatinumDiffusionTravelerApplication.accdb")
    objACC.DoCmd.OpenForm ("Switchboard"), acNormal
'    objACC.Quit
'    Set objACC = Nothing
End Sub

But it opens the form and closes it immediately.  I can use a breakpoint at End Sub to see the form is open.  And I can use it normally.  

What needs to be done to keep the form open?
Thanks,
Brooks
Comment
Watch Question

BRONZE EXPERT
Top Expert 2016
Commented:
try this revision


Private Sub btnOpenPlatinumTraveler_Click()
    Dim objACC As New Access.Application
   
    Set objACC = GetObject("T:\Diode Travelers Application\Source\DiodePlatinumDiffusionTravelerApplication.accdb")
    objACC.DoCmd.OpenForm ("Switchboard"), acNormal
    objACC.UserControl=true
'    Set objACC = Nothing
End Sub
Guy Hengel [angelIII / a3]Billing Engineer
GOLD EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
this is becaue the objACC goes out of scope, and hence closes the application (and the form).

please define the variable objAcc on your form level, and it shall work.

and you might then check if objAcc is already set , and reuse it if you are to open several forms of that same other database ...

Author

Commented:
Thanks Capricorn
Please look for my follow up question about having the form open up on top...
Brooks

Explore More ContentExplore courses, solutions, and other research materials related to this topic.