Error Message Form on certain criteria

ECEK

Registered User.
Local time
Today, 14:35
Joined
Dec 19, 2012
Messages
717
I have a form that has hours, minutes, and seconds as an imput.
Onlost and Onchange these update the [tot_secs] field with a calculation like so:
Code:
Private Sub s_Change()
Me.tot_secs = (Me.h * 3600) + (Me.m * 60) + Me.s
End Sub

What I'm trying to do is to create an error message if the field [tot_secs] = 0
the field [tot_secs] is on my form but is not enabled and is locked.

The error form is called [SecsOn]
This is what I thought would work ?
Code:
Private Sub tot_secs_BeforeUpdate(Cancel As Integer)
If Me.tot_secs = 0 Then
    DoCmd.OpenForm "SecsOn", acNormal, , , acFormReadOnly, acWindowNormal
    
   End If
   
    
End Sub

Any thought or direction is greatly appreciated.

I am also aware that I'm robably approaching this in the wrong way!! again. Advice is humbly and generously accepted.
 
it seems you would need 3 checks, s,m, & H
Code:
Private Sub s_Change()
  TotalAll
End Sub

Private Sub m_Change()
  TotalAll
End Sub

Private Sub h_Change()
  TotalAll
End Sub

private sub TotalAll()
Me.tot_secs = (Me.h * 3600) + (Me.m * 60) + Me.s
end sub

and why show a form?
cant you just show a msgbox? ... msgbox "Total = zero"
 
Try This:

Code:
Private Sub h_afterupdate()

    Me.tot_secs = (Me.h * 3600) + (Me.m * 60) + Me.s
    
    If Me.tot_secs = 0 Then
        DoCmd.OpenForm "SecsOn", acNormal, , , acFormReadOnly, acWindowNormal
    End If
    
End Sub
Private Sub m_afterupdate()

    Me.tot_secs = (Me.h * 3600) + (Me.m * 60) + Me.s
    
    If Me.tot_secs = 0 Then
        DoCmd.OpenForm "SecsOn", acNormal, , , acFormReadOnly, acWindowNormal
    End If
    
End Sub
Private Sub s_afterupdate()

    Me.tot_secs = (Me.h * 3600) + (Me.m * 60) + Me.s
    
    If Me.tot_secs = 0 Then
        DoCmd.OpenForm "SecsOn", acNormal, , , acFormReadOnly, acWindowNormal
    End If
    
End Sub
 
This works a treat. many thanks.
I didn't add all of the h m & s code in my initial post for brevity but yes: there is one for each of these.

RanMan is indeed correct: I should really use MsgBox but I was unsure of the VBA code and parameters (still am?)

My "SecsOn" form is effectively a Msgbox. It just opens and has a close form button on it.

How would one replicate the code(below) using MsgBox instead of opening the form?

Me.tot_secs = (Me.h * 3600) + (Me.m * 60) + Me.s

If Me.tot_secs = 0 Then
DoCmd.OpenForm "SecsOn", acNormal, , , acFormReadOnly, acWindowNormal
End If
 
Instead of the DoCmd.OpenForm line, put this in:

Code:
MsgBox Prompt:="Message here", Buttons:=vbCritical, Title:="Title here"

Or if you're lazy:

Code:
MsgBox "Message here", vbCritical, "Title here"
 

Users who are viewing this thread

Back
Top Bottom