Solved Backup after 6x

sergio vieira

Member
Local time
Today, 17:29
Joined
Apr 22, 2024
Messages
32
199 / 5 000
Good afternoon. Is it possible that every time I enter my application it registers and after 6 times I inform the user that it is necessary to make a backup? I appreciate the help, as I am still inexperienced in vba.Thank's
 
Do you record each login to a table?
 
Ok, i understand the idea. I think i can do that. But my problem: How do I make sure that when this happens the application goes back to 1 record and so on up to 6 and then starts again?
 
Ok, i understand the idea. I think i can do that. But my problem: How do I make sure that when this happens the application goes back to 1 record and so on up to 6 and then starts again?
You reset the value after you have done whatever you need to do at 6 logins.
 
Well you are updating it each time, so of course you can reset it.
 
How many simultaneous users on your database? If this is standalone then you could query that login table at login. If it is 7th login, then delete the first 6 and make this record 1.
If this is multiuser, then you might consider the login table to be in the front end where each user gets his/her own front end.
 
There is a serious question to consider.

1. Is this a shared (i.e. multi-user) DB for which simultaneous access is possible?
2. Is this a split database?
3. What (how much) are you backing up?
4. Is the backed-up material user-specific?"

If the answers are #1 = YES and #2 = NO then you have a big risk to consider that could lead to data corruption. But also bad is... If #1 = YES and #4 is YES then you run a risk of locking a big part of the DB under normal operation since Access shared databases don't keep separate data files per-user unless YOU programmed them that way. And worst of all (for data interference issues) is if #3's answer something in a table that is used by all users.

Tell us your DB configuration (see questions 1 & 2 above). You COULD have the potential for losing data, particularly if user data resides in a shared table and a backup restoration would overwrite this table.
 
Doc,
If multiuser, could he not record the login and UserId in a front end table. That was my first thought, but we need more environmental context.
 
Strategies in order of convenience:
1. Log sessions in a table
2. Log sessions in an external file
3. Log sessions in a registry key
4. Log sessions on the internet

The idea is to make the count of sessions persist. Once you choose a strategy, choose when to store the session.

For example, you could log the session when they enter their credentials in a login form or simply when a certain form opens if you don't have a login form.

If a form opens multiple times and you want to log only the first open per session, you could use a TempVar because they don't exist until you add them any time while the app is running, and they will persist until you close the app, so you could check if the TempVar exist and if it does not, that's your first open, if it does exist, then it's not the first open. The whole approach would require you to have a table like this:

Code:
sessions
    Id (long, pk)
    user_name (string)
    created_at (date)

Then, in a module you add this
Code:
Sub WarnEvery6Sessions(username As String, message As String, title As String)

    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT COUNT(*) AS SessionCount FROM sessions WHERE user_name = '" & username & "'")
   
    Dim sessionCount As Integer
    If Not rs.EOF Then
        sessionCount = rs!sessionCount
    End If
    rs.Close
    Set rs = Nothing

    If sessionCount > 0 And sessionCount Mod 6 = 0 Then
        MsgBox message, vbExclamation, title
    End If

    ' only log if first time opening the form in the session
    If IsNull(TempVars("firstlog")) Then
        TempVars("firstlog") = True
        CurrentDb.Execute "INSERT INTO sessions (user_name, created_at) VALUES ('" & username & "', '" & Now() & "')"
    End If
   
End Sub

And then, in the form you want this counter to make effect, you would add this:
Code:
Private Sub Form_Open(Cancel As Integer)
    ' boss is hardcoded, use a valid user name
    WarnEvery6Sessions "boss", "You should make a backup now.", "Backup recommended."
End Sub

Check the attached file to see it in action. I'm not saying this is the only way. It's just my contribution. Hope it helps.
 

Attachments

Doc,
If multiuser, could he not record the login and UserId in a front end table. That was my first thought, but we need more environmental context.

Oh, absolutely. But it is what comes next that gets interesting. And kind of complicated. Multi-user databases that are dynamically being accessed actually cannot be backed up properly unless you have a way to put them in a backup-specific mode that locks EVERY table and copies it, then copies the transaction table that holds what you did since you entered backup mode. But Access back-end operation doesn't HAVE that option. Access is a passive file sharing system, having no active parts for the BE file. Thus if person A does a backup while person B is active, you have a "moving target backup" that is going to be anywhere from simply useless to outright damaging.

If you are going to do a backup, you CAN do it, but it is best done when the database is quiescent. Otherwise you invite destructive interference, a.k.a. "Left hand doesn't know what right hand is doing."
 
Good morning to everyone. There's only one logged. I'm going to try yours advices and then put my feedback here. Thank you
 
Thanks Doc.(y) I felt the OP had a single user database. I am aware of multiuser database and a separate backup strategy typically run by an operations group when users are not active. Often at a certain time, every day or week after normal hours of work. Also case(s) where a important backup or maintenance was required during regular hours and a forced, impending shutdown with a system wide message could occur. Again triggered by someone in authority.
I recognize the turmoil that could/would happen if individual work stations could invoke a backup when other simultaneous users were working.
Thanks again for highlighting that.
 
199 / 5 000
Good afternoon. Is it possible that every time I enter my application it registers and after 6 times I inform the user that it is necessary to make a backup? I appreciate the help, as I am still inexperienced in vba.Thank's
I think this may be the wrong question to ask.
Instead of "after six logins" which could be all six done during an hour or two during a morning shift, why not do the message after a certain time period / amount of activity?

If you want a "Daily backup", I'd use a configuration record that holds last prompt date/time and what time or number of days before reminding.
 

Users who are viewing this thread

Back
Top Bottom