My question is how can I save the database path? because whenever I change computer from Home to School I need to reconnected all the database connections.. or else a "/db/.mdb is not a valid path" error pops out.. I still can't figure it out how to set a database path...
Show the line that is causing the error and it would be easier to help.
BitBlt has a good suggestion: trapping the error. Your home path for the database file and the school path shouldn't change and you should know the path names.
Private Sub ConnectToDB()
On Error GoTo DBCONNECT_ERR
Dim strDbPath as String
strDbPath = strHomePath
Set rst = New ADODB.Recordset
Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.Jet.OLEDB.4.01"
.Open strDbPath & "\db\My.mdb", ...., ,,
End with
....
....
Exit Sub
DBCONNECT_ERR:
if strDbPath = strHomePath then
strDbPath = strSchoolPath
Else
strDbPath = strHomePath
End if
cn.open strDbPath & "\db\My.mdb"
Resume Next
End Sub
This error trap just assumes that the error will be a bad path. Uuually, you want to trap the error, look at the err.Number, and then decide on what course of action to take based on the error code. But this should give you an idea. This example assumes you're at home and that you've already hard coded values for the home path and the school path in a variable that's available for the ConnectToDb sub routine.