0

Try to do 3 things.

The 1st see if a database exists in a certain location:
if it dose then connect.
else show error message.

The 2nd see if the database is open:
if open the display a message to the users that they are going to get disconnected.
pause for a length of time.
then disconnect them from the database.

The 3rd how to open the Database in exclusive mode.

Below my code and possible placing of extra code.

Writing with in Access 2003, and is a part of a unload download program.

Public Const RemoteDatabase As String = "\\RemoteDatabase\RemoteDatabase.mdb"
Public dbRemoteDatabase As New ADODB.Connection
Public rsTableRemote01 As New ADODB.Recordset
Public rsTableRemote02 As New ADODB.Recordset
Public rsTableRemote03 As New ADODB.Recordset
Public Const Table01 As String = "tblTable01"
Public Const Table02 As String = "tblTable02"
Public Const Table03 As String = "tblTable03"

Function OpenRemoteDatabase1()
If <try to see if the Database is there or not> = <true> then
If<anyone is connected to it> = <true> then
<Display message to Users that they are getting disconnected>
<Pause state 60 seconds>
<disconnect Users>
End If
If dbRemoteDatabase.State = 0 Then
dbRemoteDatabase.Open "Provider = microsoft.jet.oledb.4.0;data source=" & RemoteDatabase

rsTableRemote01.Open Table01, dbRemoteDatabase, adOpenDynamic, adLockOptimistic
rsTableRemote02.Open Table02, dbRemoteDatabase, adOpenDynamic, adLockOptimistic
rsTableRemote03.Open Table03, dbRemoteDatabase, adOpenDynamic, adLockOptimistic
End If
Else
msgbox "Database not connected" & Chr(13) & Chr(10) & "Connect and re try" , vbCritical
DoCmd.Close
End If
End Function

1
Contributor
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Zermoth
0

Public sfso

Set sfso = CreateObject("Scripting.FileSystemObject")

If sfso.FileExists(RemoteDatabase) Then
If dbRemoteDatabase.State = 0 Then
dbRemoteDatabase.Open "Provider = microsoft.jet.oledb.4.0;data source=" & RemoteDatabase

rsTableRemote01.Open Table01, dbRemoteDatabase, adOpenDynamic, adLockOptimistic
rsTableRemote02.Open Table02, dbRemoteDatabase, adOpenDynamic, adLockOptimistic
rsTableRemote03.Open Table03, dbRemoteDatabase, adOpenDynamic, adLockOptimistic
End If
Else
msgbox "Database not connected" & Chr(13) & Chr(10) & "Connect and re try" , vbCritical
DoCmd.Close
End If

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.