Having issues with .SetFocus after msgbox...
I presume the code is attached to a command button on a form?
This works for me in such a situation:
Private Sub CommandButton1_Click()
If TextBox1.Value < TextBox2.Value Then
MsgBox "The entered values do not match"
TextBox1.SetFocus
Exit Sub
End If
If TextBox1 = "" Or TextBox2 = "" Then
MsgBox "You have not verified the inputs"
If TextBox1 = "" Then
TextBox1.SetFocus
Else
TextBox2.SetFocus
End If
End If
End Sub
By the way,
If TextBox2.Value TextBox1.Value
and
If TextBox1.Value < TextBox2.Value
is the same test,
If TextBox1.Value < TextBox2.Value
takes care of inequality in either direction in one test.
" wrote:
Hello fellow programmers!
If TextBox1.Value = "" Then
MsgBox "You have not confirmed the Information." & vbNewLine & "Please
type the Information in both boxes.", , " - Information Error - "
With TextBox1
..SetFocus
End With
Exit Sub
End If
If TextBox2.Value = "" Then
MsgBox "You have not confirmed the Information." & vbNewLine & "Please
type the Information in both boxes.", , " - Information Error - "
With TextBox2
..SetFocus
End With
Exit Sub
End If
If TextBox2.Value TextBox1.Value Then
MsgBox "The Informations you have entered do not match. Please try
again.", , " - Information Error - "
With TextBox1
..SetFocus
End With
Exit Sub
End If
If TextBox1.Value < TextBox2.Value Then
MsgBox "The Informations you have entered do not match. Please try
again.", , " - Information Error - "
With TextBox2
..SetFocus
End With
Exit Sub
End If
The message box displays twice and the SetFocus doesn't work...any
ideas? Your help is much appreciated!
|