Results 1 to 7 of 7
  1. #1
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63

    Exclamation How can I prevent access from saving an incomplete record when forcing user out of the database?

    Good afternoon,

    I wrote a code on a hidden form to kick users out of the database if the current time (CurrentTime) is equal to or greater than the time I designate to kick the users out (TimeOut). Users could be in the middle of filling out a form and have an incomplete record. I need to make sure that the incomplete records don't save when they are being kicked out of the database. No matter what I try, I cannot get this to work. Right now, this is the code that I'm using:

    Private Sub Form_Timer()
    Me.Refresh
    If Me.CurrentTime >= Me.TimeOut Then


    Application.Quit (acQuitSaveNone)
    End If
    End Sub


    Can anyone help me out here?

    Thank you!

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    One way is to make your Forms unbound, so nothing is added at all until they click a button to write the entire record to the database.
    Of course, they you need to add VBA code to actually write the record to the table instead of using a bound Form.

    You also may be able to use some of the methods mentioned here: http://www.access-programmers.co.uk/...ad.php?t=73109

  3. #3
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63
    Thank you JoeM.

    I have an idea, but I don't know how to make it work. I'm thinking that if I put a code in BeforeUpdate on the form that the user is filling out, I might be able to get access to recognize a new and incomplete record. Is there any way to identify an incomplete new record versus a complete new record? I tried

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.Dirty = True Then
    Cancel = True
    End If
    End Sub

    I realize now that it won't work because any new unsaved record is considered a dirty record...

  4. #4
    MatthewR is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    118
    Well, it's incomplete if not all the fields are filled out right? So, you can check if the fields are null in the if statement:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.Dirty = True And (Field1=Null or Field2=Null or Field3=Null...) Then
    Cancel = True
    End If
    End Sub

  5. #5
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Another trick you may want to try is to make sure that you have all your required fields set properly in Table Properties (Required and Zero Length Not Allowed).
    Then if a record is incomplete, it will not add it unless all the Required Fields are filled out with valid values.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    "Application.Quit (acQuitSaveNone)" does not do what you think it does.
    The option "acQuitSaveNone" is in reference to saving DESIGN changes of objects, not DATA changes.

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    I'd give this a shot:

    Code:
    Private sub Form_Timer()
    Code:
    Me.Refresh
    If Me.CurrentTime >= Me.TimeOut Then
    Call Form_YourFormName.Form_BeforeUpdate(False)
    Application.Quit 
    End If End Sub



    YourFormName is yes, your form name.

    This demonstrates how to call a sub or function in a form module from outside the module
    You will probably have to make the existing Form_BeforeUpdate a public sub.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 09-11-2014, 12:26 PM
  2. forcing the user to choose a value
    By fabiobarreto10 in forum Forms
    Replies: 16
    Last Post: 04-15-2012, 09:52 PM
  3. Replies: 2
    Last Post: 12-07-2011, 02:51 AM
  4. Prevent Saving of Form
    By bburton in forum Access
    Replies: 4
    Last Post: 02-25-2011, 09:26 PM
  5. Replies: 2
    Last Post: 07-01-2010, 07:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums