I'm writing a word plugin which connects to a back end database. I've got the following code:-
The idea is that if the connection fails I give the user the option to configure the connection (via the configure method) or not to bother. If the user doesn't bother then the app should raise an error which will be caught at the top level and exit gracefully.Code:On Error GoTo connErr61 mConn.Open "Provider=SLXNetwork.1;User ID =" & mUserID & ";password=" & mPassword & ";Data Source = " & mDB & ";Extended Properties=""SLX Server=" & mServer & ";ADDRESS=localhost;Type=ODBC;PORT=" & mPort & """" MsgBox "open succeeded" mConn.CursorLocation = adUseClient Exit Sub connErr61: MsgBox "open failed" If MsgBox("Database connection failed. Check configuration? (Cancel will exit)", vbOKCancel, "Connection Error") = vbOK Then configure Else Err.Raise 100, "Config.Connect", "Connection Failed" End If End Sub
The trouble is that if I give it an invalid password I get a runtime error on the mConn.open line and the app bombs out immediately. Neither the "open succeeded" or "open failed" message appears and, more importantly, the code which lets the user reconfigure doesn't fire. As a result, once there's a bad password the user can't get into the app at all.
Shouldn't my "onError GoTo connErr61" force execution in to the connErr61 block?




Reply With Quote