Checking backend connection and permissions

sneuberg

AWF VIP
Local time
Yesterday, 19:28
Joined
Oct 17, 2014
Messages
3,506
Our customers have a split system with their connection to the backend over a flakey WIFI so we want to put in something in the frontend that checks for a connection to the backend when they first run the program. Also occasionally someone is provided a copy of the frontend application to use, but has not been granted adequate access to the server. The code I’m come up with so far for checking these conditions follows and I’m asking if there’s a better way to do this and whether anyone sees any problems with what I got. I googled and haven’t found any way of checking the permissions directly.

Also I should say that we have told our customers that this WIFI connection is a bad idea. In anticipation of a corrupt backend data file we have put in code that does frequent backups. But in spite of the fact that their connection comes and goes they haven’t ended up with a corrupt file. I’m wondering if this is nowadays less of a problem because of NTFS.

Public Function CheckBackend(BackendPath As String) As Boolean

If Len(Dir(BackendPath)) = 0 Then
CheckBackend = False
MsgBox "The datafile " & BackendPath & " cannot be found." & vbCrLf & _
"Please check your network connection and retry" & vbCrLf & _
"Program will be terminated"
DoCmd.Quit
ElseIf Not CheckDatabase(BackendPath) Then
CheckBackend = False
MsgBox "The datafile cannot be opened." & vbCrLf & _
"Please have your IT staff check your permissions to: " & vbCrLf & _
BackendPath & vbCrLf & _
"Program will be terminated"
DoCmd.Quit
Else
CheckBackend = True
End If

End Function

Private Function CheckDatabase(dbPath As String) As Boolean
On Error GoTo CheckDatabaseError
CheckDatabase = True

Dim db As DAO.Database
Set db = OpenDatabase(dbPath)
db.Close

CheckDatabaseExit:
Exit Function
CheckDatabaseError:
CheckDatabase = False
GoTo CheckDatabaseExit

End Function
 

Users who are viewing this thread

Back
Top Bottom