Server connection error not working

  • Thread starter Thread starter Anthony
  • Start date Start date
A

Anthony

I have a database that is on a server. The users have to connect to the
server with a userID and password before they can use it. However, since we
have laptops, we can either be connected to the network or out in the field
not connected. When we go out in the field, there is a function built into
the database that loads your data onto your harddrive so you can use the
database off-line. When you log onto the database I have this code:

Private Sub cmd_Login_Click()
On Error GoTo Code_Err

DoCmd.Hourglass True
Dim db As New ADODB.Connection

int_Connected = 1

Me.lbl_Connection.Visible = True

db.ConnectionString = Get_DBConn()
db.Open

..(Code that checks your password and userID)
..
..
Resume_Login:
Dim db_Database As DAO.Database
Dim rst_Checked_In As DAO.Recordset
Dim str_sql As String
Set db_Database = CurrentDb
str_sql = "SELECT Project_ID, Checked_In, Security_ID FROM
sys_Checked_In"
Set rst_Checked_In = db_Database.OpenRecordset(str_sql)

(Code that checks your password and UserID and determine if you have a
project checked out)
..
..
Code_Err:
If Err.Number = "-2147467259" Then
MsgBox "You do not have access to the live database at this time.
You will only be able to make changes to the project you have checked out."
int_Connected = 0
GoTo Resume_Login
Else
MsgBox Err.Description, , "#" & Err.Number
End If
Resume Code_Exit

If it tries to connect but can't find the server, ADO issues an error code
"-2147467259". As you can see from my code near the bottom, If that error
is detected, it suppose to issue a message then goto "Resume_Login". For
some reason, that is not working. Instead, the error code "-2147467259" is
displayed on the screen, and the program bombs out saying to can't find the
server.

Any help would be appreciated.
 
If Err.Number = "-2147467259" Then
MsgBox "You do not have access to the live database at this time.
You will only be able to make changes to the project you have checked out."
int_Connected = 0
GoTo Resume_Login

You are referring to the err.number as a string rather than a Long integer

try

If Err.Number = -2147467259 Then

also, i believe you need to change
GoTo Resume_Login

to

Resume Resume_Login


Also, it would be a good idea to clear the error before resuming the code

Err.Clear
Resume Resume_Login

Sometimes its easier to trap these errors where they occur rather than
sending them to the handler.

--
Jack Leach
www.tristatemachine.com

- "A designer knows he has reached perfection not when there is nothing left
to add, but when there is nothing left to take away." - Antoine De Saint
Exupery
 
Sometimes its easier to trap these errors where they occur rather
than sending them to the handler.

Could you elaborate on that? I'm prepared to disagree with the basic
proposition, but would like to hear your reasoning first, as I might
learn something useful.
 
thanks diamondjack. I will try your suggestions, though on an earlier
version of the database, the "no connection" error trapping worked fine.
After writing this question, I think I may have partially found out what is
happening by shear luck. When I lose my network connection, it takes about
3 minutes before it knows. (I don't know what "it" is - could be Access or
MS O/S). Therefore, if I try to connect before the computer recognizes I
lost my connection, I get the ODBC error. If I wait long enough, I don't
get the error - the code handles the "no connection" error properly. I
don't know why the error trapping code has a problem before the 3 minutes.
If it can't connect, the error trapping code should handle it properly.
 
Back
Top