AOB
Registered User.
- Local time
- Today, 15:05
- Joined
- Sep 26, 2012
- Messages
- 613
Hi guys,
Struggling with some odd behaviour...
I have a backup subroutine which automatically triggers when the front-end is closed down (it just takes the back-end, makes a copy and compacts it)
It's driven off a hidden form which I use to track who is connected to the BE at any given time. This form is opened as part of the AutoExec when the FE is opened and writes some basic user info to a table. When the form is closed, it updates the table and fires the backup process before quitting Access. Works a charm, no problems with that.
Part of that user tracking process checks to see if the same user is already connected - either elsewhere (i.e. on a different machine) or on the same machine (i.e. opening a second instance of the same FE) - which is undesirable (and, frankly, unlikely, but not impossible) A brief prompt appears to explain that they can only be connected once, at which point the application is quit (to enforce the rule) This also works fine.
However - it doesn't really make sense to fire the backup process in these situations, as the user is only briefly 'in' before being kicked straight back out again. So I figured I would add a public boolean variable, set it to True by default, then switch it to False if the same user is already logged on before quitting Access.
Trouble is, the variable doesn't seem to be holding its value?
Here is the Load event for the tracking form :
And then in the UnLoad event for the same form :
For some reason, blnPerformBackup is False every time, even though I set it to True at the very start of the Load event (and it is a Public variable, defined in a separate module where I store all my Public constants and variables)
Any suggestions as to why it is not retaining its value from the Load event? I've checked and it does get set to True - and when I debug, it remains True - but at runtime it reverts back to False by the time it reaches the decision whether to backup or not?
Thanks
Al
Struggling with some odd behaviour...
I have a backup subroutine which automatically triggers when the front-end is closed down (it just takes the back-end, makes a copy and compacts it)
It's driven off a hidden form which I use to track who is connected to the BE at any given time. This form is opened as part of the AutoExec when the FE is opened and writes some basic user info to a table. When the form is closed, it updates the table and fires the backup process before quitting Access. Works a charm, no problems with that.
Part of that user tracking process checks to see if the same user is already connected - either elsewhere (i.e. on a different machine) or on the same machine (i.e. opening a second instance of the same FE) - which is undesirable (and, frankly, unlikely, but not impossible) A brief prompt appears to explain that they can only be connected once, at which point the application is quit (to enforce the rule) This also works fine.
However - it doesn't really make sense to fire the backup process in these situations, as the user is only briefly 'in' before being kicked straight back out again. So I figured I would add a public boolean variable, set it to True by default, then switch it to False if the same user is already logged on before quitting Access.
Trouble is, the variable doesn't seem to be holding its value?
Here is the Load event for the tracking form :
Code:
Private Sub Form_Load()
On Error GoTo ErrorHandler
Dim dbs As Database
Dim rst As Recordset
Dim strSQL As String
Call InterfaceInitialise
[COLOR=red] blnPerformBackup = True[/COLOR]
' Check if this is the first time this user has connected
Set dbs = CurrentDb
With dbs
strSQL = "SELECT [tblConnections].* " & _
"FROM [tblConnections] " & _
"WHERE [tblConnections].[UserID] = " & Chr(34) & UCase(cSysInfo.UserName) & Chr(34)
Set rst = .OpenRecordset(strSQL)
With rst
Select Case .RecordCount
Case Is > 0 ' Returning user
' Check if already logged on elsewhere
If .Fields("Connected") = True And .Fields("Hostname") <> UCase(cSysInfo.ComputerName) Then
MsgBox "You are already logged in on another machine : " & vbCr & vbCr & _
.Fields("Hostname") & " in " & LCase(.Fields("Domain")) & vbCr & vbCr & _
"You must log off the above machine first", vbCritical, "Already Logged On?"
[COLOR=red]blnPerformBackup = False[/COLOR]
Application.Quit
' Check if already connected on same machine
ElseIf .Fields("Connected") = True Then
MsgBox "You already have this DB open?", vbCritical, "Already Logged On?"
[COLOR=red]blnPerformBackup = False[/COLOR]
Application.Quit
Else
' Update record
.Edit
.Fields("Connected") = True
.Fields("Hostname") = UCase(cSysInfo.ComputerName)
.Fields("Domain") = UCase(cSysInfo.ComputerDomain)
.Fields("LastLogon") = Now
.Update
End If
.....
And then in the UnLoad event for the same form :
Code:
If [COLOR=red]blnPerformBackup[/COLOR] Then
If Nz(BackupBackEnd, "") = "" Then MsgBox "Backup process has failed", vbCritical, "Backup Failed"
End If
For some reason, blnPerformBackup is False every time, even though I set it to True at the very start of the Load event (and it is a Public variable, defined in a separate module where I store all my Public constants and variables)
Any suggestions as to why it is not retaining its value from the Load event? I've checked and it does get set to True - and when I debug, it remains True - but at runtime it reverts back to False by the time it reaches the decision whether to backup or not?
Thanks
Al