dont run if network offline

rio

Registered User.
Local time
Tomorrow, 02:02
Joined
Jun 3, 2008
Messages
124
hi.. i got a problem with my database. i used odbc connection using oracle. sometime there is no connection.

i used this code to open the connection.

Code:
Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database
Dim tdf As DAO.TableDef
 
Set db = CurrentDb()
Set tdf = db.TableDefs("TEST")
tdf.Connect = "ODBC;DSN=PS-TEST;UID=" & UserName & ";PWD=" & PSWD & " ;driver={Microsoft ODBC for Oracle};server=PS-TEST;"
tdf.RefreshLink

DoCmd.SetWarnings False

End Sub

Is there a way that i can set this command to run only if there is a network connection. if no connection it dont run.


Please someone help me..
 
Here is a function that you can use to see if there is a vlid connection between the client and the internet.

Code:
Private Declare Function InternetGetConnectedState Lib "wininet" _
(ByRef dwFlags As Long, _
ByVal dwReserved As Long) As Long

Private Function AmICOnnected() As Long
Dim lReturn As Long
AmICOnnected = InternetGetConnectedState(lReturn, 0)
End Function

Private Sub cmdGo_Click()
If AmICOnnected = 1 Then
MsgBox "You are Connected"
Else
MsgBox "you are not connected"
End If

End Sub

In this example the Sub cmdGo is a command button click response, you could put this code in your startup form to check for an internet connection, then if not found warn user, whatever.

David
 
Thanks DCrake. I used ur code.... combine with mine... become like this :

Code:
Private Declare Function InternetGetConnectedState Lib "wininet" _
(ByRef dwFlags As Long, _
ByVal dwReserved As Long) As Long

Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim lReturn As Long
AmICOnnected = InternetGetConnectedState(lReturn, 0)
If AmICOnnected = 1 Then
MsgBox "You are Connected"
Set db = CurrentDb()
Set tdf = db.TableDefs("TEST")
tdf.Connect = "ODBC;DSN=PS-TEST;UID=" & UserName & ";PWD=" & PSWD & " ;driver={Microsoft ODBC for Oracle};server=PS-TEST;"
tdf.RefreshLink

DoCmd.SetWarnings False
Else
MsgBox "you are not connected"
End If
End Sub

It's work. Thanks again.
 
hi... can anyone help me...
is there any way that i can show in the form the last online date & time?
 
When a person logs in from a pc you need to record that in either a table or a flat txt file. Then the next time they open the app you open the table/file and read in the contents and display on form.

David
 
Code:
When a person logs in from a pc you need to record that in either a table or a flat txt file. Then the next time they open the app you open the table/file and read in the contents and display on form.

David

that about log in... how about if there was offline. i want last online date not last log in date. any suggestion? please?
 
So look at the code AmIConnected if it returns false then store that information in a txt file on the pc or in a table.

Why do you want to log when the person was not connected?

David
 
hi... Thanks for reply

Code:
So look at the code AmIConnected if it returns false then store that information in a txt file on the pc or in a table.

Can u help me how to write the code?

Code:
Why do you want to log when the person was not connected?

this database was share with a lot of people. sometime we need to know the latest data. if there was offline... we still looking for the last data.
 
Read up on Open FileName For Input/Output As #1

This will help you read/write to flat text files that can be read when the application is launched.

David
 
hi... got another problem... I used this code to check the internet connetion.
Code:
Private Declare Function InternetGetConnectedState Lib "wininet" _
(ByRef dwFlags As Long, _
ByVal dwReserved As Long) As Long

Private Function AmICOnnected() As Long
Dim lReturn As Long
AmICOnnected = InternetGetConnectedState(lReturn, 0)
End Function

Private Sub cmdGo_Click()
If AmICOnnected = 1 Then
MsgBox "You are Connected"
Else
MsgBox "you are not connected"
End If

End Sub
how about if I want to change internet connection to server connection. coz sometime when there is internet connection but no server connection.
 

Users who are viewing this thread

Back
Top Bottom