Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open DB when not connected.

Status
Not open for further replies.

sap2

Technical User
Dec 20, 2007
12
US
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.
 
Add some error handling in, you'll know what the error number is (from the errors you've received) and trap that particular error and continue on.

What I might also suggest (and I think this is better) is to use a function as intended and return a value from it (in this case whether the successful in the syncing). For example:
Code:
 Function SynchronizeDBs(strDBName As String, strSyncTargetDB As String, _
 intSync As Integer) as Boolean
 
 Dim dbs As DAO.Database
 
 On Error Goto ErrHan

 SynchronizeDBs = True

 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
 Exit Function

 ErrHan:
 msgbox "Not connected to remote DB"
 SynchronizeDBs = False
 dbs.Close
 End Function
Hope this helps


HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I'd forget about the msgbox I put in the function, just handle the returned boolean value how you want when the functions finished.

Cheers

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top