Suppress "You can't save this record at this time" (1 Viewer)

jack555

Member
Local time
Today, 09:30
Joined
Apr 20, 2020
Messages
93
Inactive timer trying to quit the access app. However, the bound form has some fields left incomplete are set to "required". This prompts the message "You can't save this record at this time" which requires user input to click yes or not; until then the app is not closed which goes against inactive timer close. DoCmd.SetWarnings False not solving this for some reason.

How to suppress this prompt "You can't save this record at this time" or any other way to handle it without requiring input from the user. Thanks in advance. Below is the actual code.
Code:
Private Sub Form_Timer()
         ' IDLEMINUTES determines how much idle time to wait for before
         ' running the IdleTimeDetected subroutine.
         Const IDLEMINUTES = 1

         Static PrevControlName As String
         Static PrevFormName As String
         Static ExpiredTime

         Dim ActiveFormName As String
         Dim ActiveControlName As String
         Dim ExpiredMinutes

         On Error Resume Next

         ' Get the active form and control name.

         ActiveFormName = Screen.ActiveForm.Name
         Me.txtOpenForm = ActiveFormName
         If Err Then
             ActiveFormName = "No Active Form"
             Err = 0
         End If

         ActiveControlName = Screen.ActiveControl.Name
         Me.txtActiveControl = ActiveControlName
             If Err Then
             ActiveControlName = "No Active Control"
             Err = 0
         End If

         ' Record the current active names and reset ExpiredTime if:
         '    1. They have not been recorded yet (code is running
         '       for the first time).
         '    2. The previous names are different than the current ones
         '       (the user has done something different during the timer
         '        interval).
         If (PrevControlName = "") Or (PrevFormName = "") _
           Or (ActiveFormName <> PrevFormName) _
           Or (ActiveControlName <> PrevControlName) Then
             PrevControlName = ActiveControlName
             PrevFormName = ActiveFormName
             ExpiredTime = 0
         Else
             ' ... otherwise the user was idle during the time interval, so
             ' increment the total expired time.
             ExpiredTime = ExpiredTime + Me.TimerInterval
         End If

         ' Does the total expired time exceed the IDLEMINUTES?
         ExpiredMinutes = (ExpiredTime / 1000) / 60
         Me.txtMinutes = ExpiredMinutes
         If ExpiredMinutes >= IDLEMINUTES Then
             ' ...if so, then reset the expired time to zero...
             ExpiredTime = 0
             'MsgBox "time expired"
             DoCmd.SetWarnings False
             DoCmd.Quit acQuitSaveNone
         End If
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:30
Joined
Oct 29, 2018
Messages
21,358
Hi. Have you tried canceling the update before quitting?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:30
Joined
Feb 28, 2001
Messages
27,001
Darn, came in too late. TheDBguy's suggestion is probably good. Force an UNDO on the form before allowing the timer to force the exit.
 

jack555

Member
Local time
Today, 09:30
Joined
Apr 20, 2020
Messages
93
Cancelling Update may undo the change done even though if all fields are filled. If all mandatory fields are completed it should not be undone, only if something left blank. Please help. Thank you.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:30
Joined
May 7, 2009
Messages
19,169
maybe you can use the Form's Error Event:
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Response = acDataErrContinue
End Sub
 

vhung

Member
Local time
Yesterday, 22:30
Joined
Jul 8, 2020
Messages
235
Inactive timer trying to quit the access app. However, the bound form has some fields left incomplete are set to "required". This prompts the message "You can't save this record at this time" which requires user input to click yes or not; until then the app is not closed which goes against inactive timer close. DoCmd.SetWarnings False not solving this for some reason.

How to suppress this prompt "You can't save this record at this time" or any other way to handle it without requiring input from the user. Thanks in advance. Below is the actual code.
Code:
Private Sub Form_Timer()
         ' IDLEMINUTES determines how much idle time to wait for before
         ' running the IdleTimeDetected subroutine.
         Const IDLEMINUTES = 1

         Static PrevControlName As String
         Static PrevFormName As String
         Static ExpiredTime

         Dim ActiveFormName As String
         Dim ActiveControlName As String
         Dim ExpiredMinutes

         On Error Resume Next

         ' Get the active form and control name.

         ActiveFormName = Screen.ActiveForm.Name
         Me.txtOpenForm = ActiveFormName
         If Err Then
             ActiveFormName = "No Active Form"
             Err = 0
         End If

         ActiveControlName = Screen.ActiveControl.Name
         Me.txtActiveControl = ActiveControlName
             If Err Then
             ActiveControlName = "No Active Control"
             Err = 0
         End If

         ' Record the current active names and reset ExpiredTime if:
         '    1. They have not been recorded yet (code is running
         '       for the first time).
         '    2. The previous names are different than the current ones
         '       (the user has done something different during the timer
         '        interval).
         If (PrevControlName = "") Or (PrevFormName = "") _
           Or (ActiveFormName <> PrevFormName) _
           Or (ActiveControlName <> PrevControlName) Then
             PrevControlName = ActiveControlName
             PrevFormName = ActiveFormName
             ExpiredTime = 0
         Else
             ' ... otherwise the user was idle during the time interval, so
             ' increment the total expired time.
             ExpiredTime = ExpiredTime + Me.TimerInterval
         End If

         ' Does the total expired time exceed the IDLEMINUTES?
         ExpiredMinutes = (ExpiredTime / 1000) / 60
         Me.txtMinutes = ExpiredMinutes
         If ExpiredMinutes >= IDLEMINUTES Then
             ' ...if so, then reset the expired time to zero...
             ExpiredTime = 0
             'MsgBox "time expired"
             DoCmd.SetWarnings False
             DoCmd.Quit acQuitSaveNone
         End If
End Sub
wow nice play
>form timer is great
>why you set IDLEtime and ExpiredTime
idleminutes value is undetermined,
if this run "If ExpiredMinutes >= IDLEMINUTES Then"
just setting this "ExpiredTime = 0" for DoCmd.Quit acQuitSaveNone
>if your time expired >=idle
maybe set

dim answer
answer='MsgBox "time expired",vbyesnocancel

if yes then
execute this
DoCmd.SetWarnings False
DoCmd.Quit acQuitSaveNone

if no
you could have time to complete required field and save
>but your formTimer set to Zero value
>then click an additional timer button to activate again your timer to 1000
>i know you can do it
just make limits of alone command "DoCmd.Quit", make contorl of it
>may this ideas only breaks your aim but i'm sure this concept work somtimes cause i used it too
 

jack555

Member
Local time
Today, 09:30
Joined
Apr 20, 2020
Messages
93
maybe you can use the Form's Error Event:
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Response = acDataErrContinue
End Sub
this works. however, ignoring all other errors and also need to be inserted in all other forms - don't know any user leaving which form before inactivity. Almost near to the solution, little more to reach.
 

jack555

Member
Local time
Today, 09:30
Joined
Apr 20, 2020
Messages
93
wow nice play
>form timer is great
>why you set IDLEtime and ExpiredTime
idleminutes value is undetermined,
if this run "If ExpiredMinutes >= IDLEMINUTES Then"
just setting this "ExpiredTime = 0" for DoCmd.Quit acQuitSaveNone
>if your time expired >=idle
maybe set

dim answer
answer='MsgBox "time expired",vbyesnocancel

if yes then
execute this
DoCmd.SetWarnings False
DoCmd.Quit acQuitSaveNone

if no
you could have time to complete required field and save
>but your formTimer set to Zero value
>then click an additional timer button to activate again your timer to 1000
>i know you can do it
just make limits of alone command "DoCmd.Quit", make contorl of it
>may this ideas only breaks your aim but i'm sure this concept work somtimes cause i used it too

this code copied from the Microsoft support page itself since I am not a coder. your solution may work but difficult for me to implement and maintain. any other thoughts?
 

vhung

Member
Local time
Yesterday, 22:30
Joined
Jul 8, 2020
Messages
235
this code copied from the Microsoft support page itself since I am not a coder. your solution may work but difficult for me to implement and maintain. any other thoughts?
sorry
>i only sight the concept
>yes codes has complete syntax for that (i always use it)
>wish you could arrived with it (only you would consider the other form functions)
>but if you want the specific syntax maybe i could share it later
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:30
Joined
May 7, 2009
Messages
19,169
then filter only that particular error:
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
    If Err.Number = 2169 Then
        '* You can't save this record at this time
        Response = acDataErrContinue
    End If
End Sub

you can also Insert the Code on Each Form:
Code:
Private Sub t()
    Dim f As AccessObject
    Dim frm As Form
    Dim m As Module
    Dim line As Long
    On Error Resume Next
    For Each f In CurrentProject.AllForms
        DoCmd.OpenForm f.Name, acDesign
        Set frm = Forms(f.Name)
    
        Set m = frm.Module
        line = m.CountOfLines + 1
        m.InsertLines line, "Private Sub Form_Error(DataErr As Integer, Response As Integer)"
        m.InsertLines line + 1, "If Err.Number = 2169 Then"
        m.InsertLines line + 2, "    Response = acDataErrContinue"
        m.InsertLines line + 3, "End If"
        m.InsertLines line + 4, "End Sub"
        Set frm = Nothing
        DoCmd.Close acForm, f.Name, acSaveYes
    Next
End Sub
 

Users who are viewing this thread

Top Bottom