Opening And Closing Databases

  • Thread starter Thread starter Learning
  • Start date Start date
How about this? Watch for word wrap.

Function OpenCloseAccess()
On Error GoTo ProcError

Dim objAccess As Object
Set objAccess = CreateObject("Access.Application")

objAccess.OpenCurrentDatabase ("Path to your DB") 'Example: ("C:\codescratch\db1.mdb")

' Insert your code here.....

' and close the database when you are finished.
objAccess.CloseCurrentDatabase

ExitProc:
Set objAccess = Nothing
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, , "Error in OpenCloseAccess event
procedure..."
Resume ExitProc
End Function

________________________________________________

What is the vb code to open and close a database. I use
MS access XP. Thanks
 
Thank you, If I have two databases open at one time can I
specify in the close command which database to close? and
therefore keep the other one open. thanks again.
-----Original Message-----
How about this? Watch for word wrap.

Function OpenCloseAccess()
On Error GoTo ProcError

Dim objAccess As Object
Set objAccess = CreateObject("Access.Application")

objAccess.OpenCurrentDatabase ("Path to your
DB") 'Example: ("C:\codescratch\db1.mdb")
' Insert your code here.....

' and close the database when you are finished.
objAccess.CloseCurrentDatabase

ExitProc:
Set objAccess = Nothing
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " &
Err.Description, , "Error in OpenCloseAccess event
 
Back
Top