Reputation: 37
So I looked around a lot here and couldn't find the answer to my problem. At least not completely.
Here's the case:
I am in DBase1 and want to click a button and open the form NeuSteckbrief in DBase2 in a separate instance of access.
I amanaged to open DBase2 in a separate instance with this code:
Private Sub SteckbriefDB_Click()
Dim dq As String
Dim strExe As String
Dim strMdb As String
Dim strRun As String
Dim dblReturnVal As Double
dq = """"
'Define var strExe; Miscosoft Access
strExe = "C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE"
'Define var strMdb; Steckbrief database location
strMdb = "Correct Path\SteckbriefDB.accdb"
'Define the entire statement to implement at Shell
strRun = dq & strExe & dq & " " & dq & strMdb & dq
'Run the code to open the project database
dblReturnVal = Shell(strRun, vbMaximizedFocus)
End Sub
My problem is in opening the form NeuSteckbrief in the just opened DB. I tried to add DoCmd.OpenForm "NeuSteckbrief", acNormal but that's not working.
Do you have an idea how to adjust my code in a way that I open the DB and the correct form?
Upvotes: 2
Views: 1885
Reputation: 32632
You should really use OLE automation for something like this:
Private Sub SteckbriefDB_Click()
Dim strMdb As String
'Define var strMdb; Steckbrief database location
strMdb = "Correct Path\SteckbriefDB.accdb"
Dim appSecondInstance As New Access.Application
With appSecondInstance
.Visible = True
.UserControl = True
.OpenCurrentDatabase strMdb
.DoCmd.OpenForm "NeuSteckbrief", acNormal
End With
End Sub
Upvotes: 2