Question : VBA to open an Access database from inside another Access db.

Not sure why the code below is not working.  I'm intending to open an Access database with "strDS", but have not been successful.  My server path (//myserver1/Database.accdb) is listed on the [txtTarget] control of another form.  The database opens, but then closes immediately.  

Any ideas as to what I'm doing wrong?  Also, I'm open to any alternative ways to go about this that are better than what I'm doing now.  Thanks!

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Private Sub cmdNo_Click()
Dim objACC As New Access.Application
Dim strDSF As String
strDSF = [Forms]![frmMain]![txtTarget]


Set objACC = GetObject(strDSF)
Set objACC = Nothing

End Sub

Answer : VBA to open an Access database from inside another Access db.

test this

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Private Sub cmdNo_Click()
Dim accObj As New Access.Application
Dim strDSF As String
strDSF = [Forms]![frmMain]![txtTarget]

    With accObj
        .OpenCurrentDatabase strDSF
        .Visible = True
        .UserControl = True
    End With
   
    Set accObj = Nothing

End Sub
Random Solutions  
 
programming4us programming4us