I have a file that will be located on different network paths in different offices across the country. I have my code working mostly right to delete all the tables and relink them based on what office the user picks from a combo box. It works when a user picks the correct office that they are physically in, and it also works if they pick an office that I haven't set up yet (returns error msg that the office isnt' set up yet). The problem occurs when the user is physically in Tampa, but picks another office, such as Milwaukee, that is setup, but the network path doesn't exist because they aren't in that office.
The error seems to be happening in the Dir() function. I get a runtime error 68. Device unavailable.
I'm not so good with error trapping (access or vba isn't my best skill), but my guess is there is a way to catch this error to produce a msgbox and make the user pick again, without breaking the code. Can someone help? I'm even open for completely different ways of handling this process. Thanks.
The error seems to be happening in the Dir() function. I get a runtime error 68. Device unavailable.
I'm not so good with error trapping (access or vba isn't my best skill), but my guess is there is a way to catch this error to produce a msgbox and make the user pick again, without breaking the code. Can someone help? I'm even open for completely different ways of handling this process. Thanks.
Code:
Private Sub linkTables()
Dim dbPath As String
Dim tdf As TableDef
Dim x As Boolean
x = False
For Each tdf In CurrentDb.TableDefs
If tdf.Attributes And dbAttachedTable Then
CurrentDb.TableDefs.Delete tdf.name
End If
Next
Dim mkt As String
mkt = Me!cmbMarket
Select Case Trim(mkt)
Case "Tampa FL"
dbPath = "E:\ProviderTRAC\data\ProviderTRAC_DATA.mdb"
x = True
Case "Milwaukee WI"
dbPath = "v:\network_dept\providertrac\data\ProviderTRAC_DATA.mdb"
x = True
Case Else
'insert error msg
x = False
End Select
'MsgBox Dir(dbPath)
If x = True Then
If Dir(dbPath, vbNormal) <> "" Then
DoCmd.TransferDatabase acLink, "Microsoft Access", dbPath, acTable, "Providers", "Providers"
DoCmd.TransferDatabase acLink, "Microsoft Access", dbPath, acTable, "Groups", "Groups"
DoCmd.TransferDatabase acLink, "Microsoft Access", dbPath, acTable, "GrpNotes", "GrpNotes"
DoCmd.TransferDatabase acLink, "Microsoft Access", dbPath, acTable, "Hospitals", "Hospitals"
DoCmd.TransferDatabase acLink, "Microsoft Access", dbPath, acTable, "Markets", "Markets"
DoCmd.TransferDatabase acLink, "Microsoft Access", dbPath, acTable, "ProvNotes", "ProvNotes"
DoCmd.TransferDatabase acLink, "Microsoft Access", dbPath, acTable, "Users", "Users"
DoCmd.TransferDatabase acLink, "Microsoft Access", dbPath, acTable, "Zipcodes", "Zipcodes"
CurrentDb.TableDefs.Refresh
Else
'insert error msg
End If
Else
'insert error msg
End If
End Sub