jdawg_1989
New Member
- Joined
- Jun 24, 2011
- Messages
- 27
Afternoon All,
I have some VBA code that looks to see if an Access Database is open, if it is it switch's to the database.
If not it opens up the Access DB
The problem is, it opens the access DB and then it closes straight away, and I can't understand why.
Here is my code:
I have some VBA code that looks to see if an Access Database is open, if it is it switch's to the database.
If not it opens up the Access DB
The problem is, it opens the access DB and then it closes straight away, and I can't understand why.
Here is my code:
Code:
Global oApp As Object
Sub OpenAccess()
On Error Resume Next
Dim LPath As String
Dim LCategoryID As Long
Dim DATABASE As String
Dim oApp As Access.Application
DATABASE = "C:\Users\Joe Bloggs\Desktop\Databases\DB1\DB1.mdb"
Set oApp = GetObject(, "Access.Application")
If (Err.Number <> 0) _
Or (oApp.CurrentDb.Name <> DATABASE) Then
Set oApp = Nothing
Set oApp = CreateObject("Access.Application")
oApp.Visible = True
oApp.OpenCurrentDatabase DATABASE
Set oApp = CreateObject("Access.Application")
oApp.Visible = True
oApp.OpenCurrentDatabase DATABASE
End If
'Open form called Categories filtering by CategoryID
LLocation = Range("A2").Value
oApp.DoCmd.OpenForm "ReviewEBDOrdersFrm", , , "[Circuit]=" & "'" & LLocation & "'"
End Sub