View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Alok Alok is offline
external usenet poster
 
Posts: 318
Default Check UserForm Values Before Saving

Hi Mickey,
How about setting focus within each
if statement like this



"MBlake" wrote:

Hi Alok,
Your code works well and produces one MsgBox, however is there any way to
then SetFocus to the first missing entry?. In the code I was using the
SetFocus shelps the user. I guess I could default the SetFocu by adding
ComboBoxPIN.SetFocus as in

If sMsg < "" Then
MsgBox sMsg
Exit Sub
ComboBoxPIN.SetFocus
End If

Best Wishes,
Mickey


"Alok" wrote in message
...
Hi Mickey,
My suggestion will be to use a routine such as follows behind the 'Submit'
button, which I have here assumed is called butSubmit.

Sub butSubmit_Click()

Dim sMsg$

If ComboBoxPIN.Text = "" Then
sMsg = sMsg & "You Must Enter a PIN Number." & vbCrLf
End If

If Me.ComboBoxDate.Value = "" Then
sMsg = sMsg & "You Must Enter a Date." & vbCrLf
End If

< similar other checks

If sMsg < "" Then
MsgBox sMsg
Exit Sub
End If

<following code then copies the userform values to the database worksheet

'This will unload the form
Unload Me

End Sub

Here the advantage is that a dialog box points out all the problems with
the
data together. If the user does not fix all the problems, the submit
button
does not exit from the form and does not save to the database sheet.

Alok Joshi
"MBlake" wrote:

Hi,
Prio to saving UserForm values to a worksheet I want to verify that a
user
has completed all sections on the form. I have written the following
code
that traps the missing entries and displays a dialog box. Unfortunately
the
dialog box then closes and rather than SetFocus the data is transferred
to
the database worksheet. How can I stop the code to force the user to
complete the missing entry and click the 'Submit' buttton?

Thanks for any help,
Mickey
================================================== ========================
If ComboBoxPIN.Text = "" Then MsgBox "You Must Enter a PIN Number."
ComboBoxPIN.SetFocus
ElseIf Me.ComboBoxDate.Value = "" Then
MsgBox "You Must Enter a Date."
ComboBoxDate.SetFocus
ElseIf ComboBoxArea.Text = "" Then
MsgBox "You Must Enter a Location for this activity."
ComboBoxArea.SetFocus
ElseIf ComboBoxActivity.Text = "" Then
MsgBox "You Must Enter an Activity."
ComboBoxActivity.SetFocus
ElseIf ComboBoxOffence.Text = "" Then
MsgBox "You Must Enter an Offence."
ComboBoxOffence.SetFocus
ElseIf TextBox11.Text = "" Then
MsgBox "You Must Enter a Reference Number."
TextBox11.SetFocus
Exit Sub
End If

<following code then copies the userform values to the database
worksheet