Full Version: Msg Box
UtterAccess Forums > Microsoft® Access > Access Forms
grahamjayzee
Hi All,
thought this was going to be simple...
I have my eTimesheet working pretty well, but want to tidy up how non-standard input is handled.
Normally a form is opened and the operator selects his name and his job from a combo box. He then clicks the start/ stop button, or the various non-productive buttons. No problems here.
What I want is a simple message box that pops up if he tries to start a job before entering his name and/ or job. I presumed that the place to call this would be in the code for the start/ stop button, as it's only when the job is started that it matters that a job is not present!
Is this the best way to do this?
My code for the start stop button is:
Private Sub tog1_Click()
'Functions like a stop watch
Select Case Me.tog1
Case True ' toggle button is pressed
txtStart1.Value = Now()
Me.Detail.BackColor = RGB(200, 0, 25) 'Red (yuk)
txtMessage.Value = "Timer Running"
Case False ' toggle button is released
Tog2 = False
tog3 = False
tog4 = False
tog5 = False
tog6 = False
tog7 = False
txtStop1.Value = Now()
txtMessage.Value = "Stopped"
Me.Detail.BackColor = -2147483633 'Default background control colour
'Put time in first review handle time box (hour, minute, second)
Me.txtHandleTime1 = TimeSerial(0, 0, DateDiff("s", Me.txtStart1, Me.txtStop1))
DoCmd.GoToRecord , , acNewRec
End Select
End Sub

My combo boxes for operator and job are:
cmbOperator
cmbJobID
I had imagined it would be as simple as something like:
If Me.cmbOperator is null Then MsgBox "Enter Operator Name",vbOK
somewhere after the Case = True statement.
Anyone got any ideas?
Graham
Doug Steele
If I'm understanding you correctly...
!--c1-->
CODE
Private Sub tog1_Click()
  
'Functions like a stop watch
  Select Case Me.tog1
    Case True ' toggle button is pressed
      If IsNull(Me.cmbOperator) Then
        MsgBox "Enter Operator Name",vbOK
      Else
        txtStart1.Value = Now()
        Me.Detail.BackColor = RGB(200, 0, 25) 'Red (yuk)
        txtMessage.Value = "Timer Running"
      End If
    Case False ' toggle button is released
      Tog2 = False
      tog3 = False
      tog4 = False
      tog5 = False
      tog6 = False
      tog7 = False
      txtStop1.Value = Now()
      txtMessage.Value = "Stopped"
      Me.Detail.BackColor = -2147483633 'Default background control colour
'Put time in first review handle time box (hour, minute, second)
      Me.txtHandleTime1 = TimeSerial(0, 0, DateDiff("s", Me.txtStart1, Me.txtStop1))
      DoCmd.GoToRecord , , acNewRec
  End Select
  
End Sub
grahamjayzee
Thanks Doug,
That's a lot further than I got!
How do I check for the presence of a record in cmbJobID as well? I'm sorry, but as you can no doubt tell, I'm no code expert!
Graham
Doug Steele
Does it make sense to have the False condition work if either the operator or the job is missing?

I'd probably go with:
!--c1-->
CODE
Private Sub tog1_Click()
Dim strMessage As String
  
  If IsNull(Me.cmbOperator) Then
    strMessage = strMessage & "Enter Operator Name." & vbCrLf
  End If
  
  If IsNull(Me.cmbJobId) Then
    strMessage = strMessage & "Enter Job Id." & vbCrLf
  End If
  
  If Len(strMessage) > 0 Then
    MsgBox strMessage
  Else
'Functions like a stop watch
    If Me.tog1 = True Then ' toggle button is pressed
      txtStart1.Value = Now()
      Me.Detail.BackColor = RGB(200, 0, 25) 'Red (yuk)
      txtMessage.Value = "Timer Running"
    Else ' toggle button is released
      Tog2 = False
      tog3 = False
      tog4 = False
      tog5 = False
      tog6 = False
      tog7 = False
      txtStop1.Value = Now()
      txtMessage.Value = "Stopped"
      Me.Detail.BackColor = -2147483633 'Default background control colour
'Put time in first review handle time box (hour, minute, second)
      Me.txtHandleTime1 = TimeSerial(0, 0, DateDiff("s", Me.txtStart1, Me.txtStop1))
      DoCmd.GoToRecord , , acNewRec
    End If
  End If
  
End Sub

(given that the toggle button can only be true or false, I didn't see the need for the Case statement!)
Incidentally, what happens if they change either the selected Operator or Job between the two clicks?
grahamjayzee
Thanks again Doug,
can follow this; praise be!
There's one small problem; if I ow start the timer without entering an operator or job, I get the message box. However, the start/ stop button remains pressed, but a start time is not recorded. This means that once I click the msg box off the screen and enter an operator and job, I get an error because I have a null value in the timestart box.
Any ideas?
Doug Steele
Untested, but see whether changing
!--c1-->
CODE
  If Len(strMessage) > 0 Then
    MsgBox strMessage
  Else

to
CODE
  If Len(strMessage) > 0 Then
    MsgBox strMessage
    Me.tog1 = False
  Else

works.
grahamjayzee
Doug, you're a very clever man!
Thank you, my friend, I'm now back in the game.
Graham
Doug Steele
You're welcome.
ncidentally, the first solution I'd proposed (where the check for the operator was in the Case True secton) would have had the same problem...
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.