Why do I get an overflow error?

Anonymous
2021-12-22T00:42:50+00:00

The intISecs is a long data type and there are times when I get an overflow error. Sometimes it is when the event first occurs and other times in the middle. The event for this is a timer. Why do I get this kind of error?

Microsoft 365 and Office | Access | For business | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Anonymous
    2021-12-23T01:03:06+00:00

    Debug.print your variables (mdat_StartCountdownTime) and examine what is being passed to the function. This will quickly enlighten you at to the issue.

    If you look at your Load event, you do not always set a value for mdat_StartCountdownTime, that is normally dangerous. We still don't know how you've declared the mdat_StartCountdownTime variable?

    Is this a logoff utility? If so, why reinvent the wheel!

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2021-12-23T00:38:08+00:00

    I do have a long type. I have a hidden form name frmLogoutStatus that opens when the database is opened through the autoexec macro. When this hidden form is opened this Load event code executes. Every 10 seconds, the timer event code executes seen below. However, within the first 10 seconds I get an error indicating 'Overflow'. I dont know why.

    Private Sub Form_Load()

    On Error GoTo Err_Close_Jobs

    Dim intISecs As Long

    Dim strSelect As String

    Dim var As Variant

    Dim db As DAO.Database

    strSelect = "Select Settings.Logoff " & vbCrLf & "From Settings In 'T:\eng\Lopez\Early Stage Order Tracking_be.accdb'"

    Set db = CurrentDb

    var = db.OpenRecordset(strSelect)(0)

    If Nz(var, 0) = "True" Then

    mdat_StartCountdownTime = Now()

    End If

    Form.TimerInterval = 10000

    Exit_Close_Jobs:

    Exit Sub

    Err_Close_Jobs:

    MsgBox Err.Number & "/" & Err.Description

    Resume Exit_Close_Jobs

    End Sub

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    Private Sub Form_Timer()

    On Error GoTo Err_Close_Jobs

    Dim intIMins As Integer

    Dim intISecs As Long

    Dim strSelect As String

    Dim var As Variant

    Dim db As DAO.Database

    strSelect = "Select Settings.Logoff " & vbCrLf & "From Settings In 'T:\eng\Lopez\Early Stage Order Tracking_be.accdb'"

    Set db = CurrentDb

    var = db.OpenRecordset(strSelect)(0)

    If Nz(var, 0) = "True" Then

    intISecs = DateDiff("s", mdat_StartCountdownTime, Now())

    Debug.Print intISecs

    'Display the current seconds remaining in the 'text box corner of form

    If intISecs = 0 And intISecs < 11 Then

    DoCmd.OpenForm "frmLogoutStatus", acNormal

    Me.txtCounter.Value = "Less then 5 min"

    End If

    If intISecs > 179 And intISecs < 189 Then

    DoCmd.OpenForm "frmLogoutStatus", acNormal

    Me.txtCounter.Value = "Less than 2 min"

    End If

    'If the Seconds Counter (TimerCount) is now equal

    'to 40 seconds then the text color changed to Red

    If intISecs > 239 And intISecs < 249 Then

    DoCmd.OpenForm "frmLogoutStatus", acNormal

    Me.txtCounter.ForeColor = vbRed

    Me.txtCounter.Value = "Less then 1 min"

    End If

    If intISecs > 279 And intISecs < 289 Then

    DoCmd.OpenForm "frmLogoutStatus", acNormal

    Me.txtCounter.ForeColor = vbRed

    Me.txtCounter.Value = "Less then 20 seconds"

    End If

    If intISecs > 289 And intISecs < 298 Then

    DoCmd.OpenForm "frmLogoutStatus", acNormal

    Me.txtCounter.ForeColor = vbRed

    Me.txtCounter.Value = "Less then 20 seconds"

    End If

    If intISecs > 300 Then

    'Close the Access Program when the counter is equal to 61 seconds

    DoCmd.Quit acQuitSaveAll

    End If

    Else

    Form.TimerInterval = 0

    DoCmd.Close acForm, "frmLogoutStatus"

    DoCmd.OpenForm "CrisisAverted", , , , , acDialog

    Exit Sub

    End If

    Exit_Close_Jobs:

    Exit Sub

    Err_Close_Jobs:

    MsgBox Err.Number & "/" & Err.Description

    Resume Exit_Close_Jobs

    End Sub

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2021-12-23T00:37:31+00:00

    Well I have a hidden form name frmLogoutStatus that opens when the database is opened through the autoexec macro. When this hidden form is opened this Load event code executes. Every 10 seconds, the timer event code executes seen below. However, within the first 10 seconds I get an error indicating 'Overflow'. I dont know why.

    Private Sub Form_Load()

    On Error GoTo Err_Close_Jobs

    Dim intISecs As Long

    Dim strSelect As String

    Dim var As Variant

    Dim db As DAO.Database

    strSelect = "Select Settings.Logoff " & vbCrLf & "From Settings In 'T:\eng\Lopez\Early Stage Order Tracking_be.accdb'"

    Set db = CurrentDb

    var = db.OpenRecordset(strSelect)(0)

    If Nz(var, 0) = "True" Then

    mdat_StartCountdownTime = Now()

    End If

    Form.TimerInterval = 10000

    Exit_Close_Jobs:

    Exit Sub 
    

    Err_Close_Jobs:

    MsgBox Err.Number & "/" & Err.Description 
    
    Resume Exit\_Close\_Jobs 
    

    End Sub

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    Private Sub Form_Timer()

    On Error GoTo Err_Close_Jobs

    Dim intIMins As Integer

    Dim intISecs As Long

    Dim strSelect As String

    Dim var As Variant

    Dim db As DAO.Database

    strSelect = "Select Settings.Logoff " & vbCrLf & "From Settings In 'T:\eng\Lopez\Early Stage Order Tracking_be.accdb'"

    Set db = CurrentDb

    var = db.OpenRecordset(strSelect)(0)

    If Nz(var, 0) = "True" Then

     intISecs = DateDiff("s", mdat\_StartCountdownTime, Now()) 
    
       Debug.Print intISecs 
    
     'Display the current seconds remaining in the 'text box corner of form 
    
     If intISecs = 0 And intISecs &lt; 11 Then 
    
     DoCmd.OpenForm "frmLogoutStatus", acNormal 
    
     Me.txtCounter.Value = "Less then 5 min" 
    
     End If 
    
     If intISecs &gt; 179 And intISecs &lt; 189 Then 
    
     DoCmd.OpenForm "frmLogoutStatus", acNormal 
    
     Me.txtCounter.Value = "Less than 2 min" 
    
     End If 
    
     'If the Seconds Counter (TimerCount) is now equal 
    
     'to 40 seconds then the text color changed to Red 
    
     If intISecs &gt; 239 And intISecs &lt; 249 Then 
    
     DoCmd.OpenForm "frmLogoutStatus", acNormal 
    
     Me.txtCounter.ForeColor = vbRed 
    
     Me.txtCounter.Value = "Less then 1 min" 
    
     End If 
    
     If intISecs &gt; 279 And intISecs &lt; 289 Then 
    
     DoCmd.OpenForm "frmLogoutStatus", acNormal 
    
     Me.txtCounter.ForeColor = vbRed 
    
     Me.txtCounter.Value = "Less then 20 seconds" 
    
     End If 
    
     If intISecs &gt; 289 And intISecs &lt; 298 Then 
    
     DoCmd.OpenForm "frmLogoutStatus", acNormal 
    
     Me.txtCounter.ForeColor = vbRed 
    
     Me.txtCounter.Value = "Less then 20 seconds" 
    
     End If 
    
     If intISecs &gt; 300 Then 
    
     'Close the Access Program when the counter is equal to 61 seconds 
    
       DoCmd.Quit acQuitSaveAll 
    
    End If 
    

    Else

    Form.TimerInterval = 0 
    
    DoCmd.Close acForm, "frmLogoutStatus" 
    
    DoCmd.OpenForm "CrisisAverted", , , , , acDialog 
    
    Exit Sub 
    

    End If

    Exit_Close_Jobs:

    Exit Sub 
    

    Err_Close_Jobs:

    MsgBox Err.Number & "/" & Err.Description 
    
    Resume Exit\_Close\_Jobs 
    

    End Sub

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2021-12-22T04:32:50+00:00

    the overflow is due to the value being greater than the maximum allowable for the data type

    in this case you have more seconds that an Integer data type can handle, roughly + or - 32,767

    try using a Long data type

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2021-12-22T02:01:41+00:00

    Can you give some concrete examples?

    Where does mdat_StartCountdownTime come from? How is it calculated? How is it declared? Will it ever be Null?

    On a side note, please post your code as text rather than images, it facilitates us helping you. This way we don't have to type things out.

    Was this answer helpful?

    0 comments No comments