Start DB when not connected to network

S

SAP2

Scenario:
Currently calling the function SynchronizeDBs in the On Open Event of the
Start-up form. The function is called out as follows:
=SynchronizeDBs("C:\Documents and Settings\...\IDB
HubR1.mdb","\\ww007\...IDB Hub.mdb",1)

The function code is:
Function SynchronizeDBs(strDBName As String, strSyncTargetDB As String, _
intSync As Integer)

Dim dbs As DAO.Database

Set dbs = DBEngine(0).OpenDatabase(strDBName)

Select Case intSync
Case 1 'Synchronize replicas (bidirectional exchange).
dbs.Synchronize strSyncTargetDB, dbRepImpExpChanges
Case 2 'Synchronize replicas (Export changes).
dbs.Synchronize strSyncTargetDB, dbRepExportChanges
Case 3 'Synchronize replicas (Import changes).
dbs.Synchronize strSyncTargetDB, dbRepImportChanges
Case 4 'Synchronize replicas (Internet).
dbs.Synchronize strSyncTargetDB, dbRepSyncInternet
End Select

dbs.Close
End Function

So in this case it is performing a direct bidirectional exchange when the DB
starts up.

Problem (what I am trying to solve):
If the DB is not connected to the server it shows a runtime error and will
only let me end or debug. The DB start-form will not run.

I would like for the remote users to be able to enter the DB even if not
connected. So I would like for the function to run, but on error continue to
open the DB normally. For me that would ensure that when they are connected
the information exchange is intact, but when not connected they can still use
the DB without any interruption.

I hope this is clear. I am not an access expert or a vba expert so
suggestions of an alternative to get to the end would be helpful also. Thank
you in advance.
 
D

Douglas J. Steele

The simplest approach would be to prompt the user.

Function SynchronizeDBs(strDBName As String, strSyncTargetDB As String, _
intSync As Integer)

Dim dbs As DAO.Database

if MsgBox("Are you connected to the network?", _
vbYesNo + vbQuestion) = vbYes Then

Set dbs = DBEngine(0).OpenDatabase(strDBName)

Select Case intSync
Case 1 'Synchronize replicas (bidirectional exchange).
dbs.Synchronize strSyncTargetDB, dbRepImpExpChanges
Case 2 'Synchronize replicas (Export changes).
dbs.Synchronize strSyncTargetDB, dbRepExportChanges
Case 3 'Synchronize replicas (Import changes).
dbs.Synchronize strSyncTargetDB, dbRepImportChanges
Case 4 'Synchronize replicas (Internet).
dbs.Synchronize strSyncTargetDB, dbRepSyncInternet
End Select

dbs.Close
End If

End Function

A more sophisticated approach would be to use code like what Randy Birch has
at http://vbnet.mvps.org/code/network/isnetworkalive.htm to detect whether
they're connected. (Of course, it's possible that they could be connected,
but to the wrong network...)
 
S

SAP2

Douglas,
Thank you!! Your addition was exactly what I needed. Sometimes the DB will
run really slow through VPN so the option is a perfect idea.

I saw Randy Birch's code during my search. I am not that sophisticated.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top