dcsimg
Results 1 to 13 of 13

Thread: [RESOLVED] Show msgbox if Access Database has not been saved to backup

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Posts
    429

    Resolved [RESOLVED] Show msgbox if Access Database has not been saved to backup

    Hi
    In my project I have an Edit Form when I load the Text Boxes
    at the same time I save all page entries to Variable's so I can
    check if something has changed.
    if changes have been made I invite the user through a msgbox
    to save the DB to a another location off the user's computer.
    Now to the point I would like help with if the user does not save
    the DB when they load the program next time they get the same
    reminder with the number of days that have passed since there
    last Backup
    I have tried google and the forum but I cannot seem to find what
    I want can somebody help me please.

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,238

    Re: Show msgbox if Access Database has not been saved to backup

    simply use fileexists function to see if the backup was done,
    then use FileDateTime function to get the date it was last modified.
    Then, its a simple subtraction from todays date and the filedatetime.

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,999

    Re: Show msgbox if Access Database has not been saved to backup

    I would take a bit different route and use an INI file
    I would write the date of the last backup to the file when they actually do the backup [assuming it was successful of course]
    Then on start up I would read the value from the ini file and compare using datediff() then prompt as required

    The file exists method would be ok assuming that you are not allowing the user to choose a location and.or filename which could complicate things a bit

  4. #4
    Member
    Join Date
    Feb 2013
    Posts
    58

    Re: Show msgbox if Access Database has not been saved to backup

    INI file is high level,i dont know how to do that but i solved a similar problem once
    put a table in ur database, add the filed for last back up date
    while backing up that database, make that day's date to save on to that table's field (on a successful back up)
    then while loading the form bring that table field to compare...
    write few lines to pop up the msgbox if the last back up was too old ....
    hope it helps

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,999

    Re: Show msgbox if Access Database has not been saved to backup

    Using an INI file is not hard, there are many working examples on the net.

    Of course if you are using a database adding a table for that sort of thing would be an option
    I would use an INI file simply because I would already be using an ini file to tell the program how to connect to the database anyway so it is just one more entry in the ini file

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Show msgbox if Access Database has not been saved to backup

    In the case where the user can select the backup file name etc, the INI could contain something like
    Code:
    [LastBackup]
    Database = F:\Backup\Database.mdb
    Date = 04/11/2013
    You could read the 'Database=' item, check if it exists and then, as has been suggested already, use DateDiff to determine the number of days between today and the 'Date=' data.

    The only issue I see is that the user is saving to a location "off the user's computer". If, for whatever reason, that location is not available the 'fileexists' method might not be good enough to be able to determine whether the target location is not available (e.g. a network share is disconnected), or whether it is, but the file does not exist (e.g. it's been deleted)
    Last edited by Doogle; Nov 6th, 2013 at 02:43 AM.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Posts
    429

    Re: Show msgbox if Access Database has not been saved to backup

    Hi
    I have been reading on the net about Ini file v xml and I am still a little
    confused Doogle a Power Poster has said use Ini so that should be OK for what I want
    Ok So I next read about a simple Ini File but at this point it seems anything but simple
    I understand I have to put the API's in a module but how I save the backup date I
    cannot figure, and I have to read the date to compare.
    Could someone give me some starter code please

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Posts
    429

    Re: Show msgbox if Access Database has not been saved to backup

    Hi
    I have been reading on the net about Ini file v xml and I am still a little
    confused Doogle a Power Poster has said use Ini so that should be OK for what I want
    Ok So I next read about a simple Ini File but at this point it seems anything but simple
    I understand I have to put the API's in a module but how I save the backup date I
    cannot figure, and I have to read the date to compare.
    Could someone give me some starter code please

  9. #9
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,238

    Re: Show msgbox if Access Database has not been saved to backup

    see post #6...pretty easy

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Posts
    429

    Re: Show msgbox if Access Database has not been saved to backup

    Hi SamOscarBrown

    That's the one I have been trying to understand for a
    Power Poster such as yourself it maybe easy but for me
    as a first project I afraid not so easy

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,999

    Re: Show msgbox if Access Database has not been saved to backup

    Basically it works with 2 API routines GetPrivateProfileString and WritePrivateProfileString

    Typically I use a wrapper around these in a module and then call the wrapper to do the work

    What is shown in post #6 is a sample of what the INI file entries may look like not the code that would read or write them.

  12. #12
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,999

    Re: Show msgbox if Access Database has not been saved to backup

    have a look here
    http://www.vbforums.com/showthread.p...WRITING-TO-INI

    That code uses wrappers around the API in the form of
    Code:
    Public Sub WriteINI(wiSection As String, wiKey As String, wiValue As String, wiFile As String)
    
    Public Function ReadINI(riSection As String, riKey As String, riFile As String, riDefault As String)
    To use these you need to pass parameters and get the return value so you might do something like

    Code:
    'to read the last backup entry from the file
    LastBackup=ReadIni("Backups","LastBackup","MyConfig.Ini","1/1/1990")
    Code:
    'to write the current date as the date of last backup
    WriteINI "Backups","LastBackup",Date, "MyConfig.Ini"
    Last edited by DataMiser; Nov 6th, 2013 at 04:42 PM.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Posts
    429

    Re: Show msgbox if Access Database has not been saved to backup

    Hi DataMiser
    Thank you for your excellent INI example I have now tested this and have added
    it to my project and it does what I wanted.
    I am not sure if the experts would choose to do it the way I have but it does work
    if the update is not done it posts a old date 1/1/1900 and I use that to force the
    update the next time the program is loaded.
    See my code below
    Code:
    VB6
    Private Sub mySetUpdate()
    Dim myDiff As Integer
    Dim myBackup As Date
    myBackup = #1/1/1900#
    
    If CDate(LastBackup) = #1/1/1900# Then
        'update not done force update now
          myRetrOption = True
          frmDrvSelection.cmdSave.Visible = True
          frmDrvSelection.Show vbModal, Me
    ElseIf CDate(LastBackup) = CDate(myBackup) Then
          'update was done no further action
    Else
        'Updates may be required if 30 days past
        myDiff = DateDiff("d", CDate(LastBackup), Now)
        If myDiff >= 30 Then
            myRetrOption = True
            frmDrvSelection.cmdSave.Visible = True
            frmDrvSelection.Show vbModal, Me
        End If
    End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width