Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Having issues with .SetFocus after msgbox...

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!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default 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!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Having issues with .SetFocus after msgbox...

You don't say which message is displayed twice and which textbox you expect
to get the focus, but here's some comments:

If TextBox2.Value TextBox1.Value
is the same as
If TextBox1.Value < TextBox2.Value

I assume you meant to test if one was either greater than or less than the
other. If that's so why not just test if they are not equal:
If TextBox1.Value < TextBox2.Value

Also, I think you want to turn all of your code into one If, Else, Endif
statement, like this:

If TextBox1.Value = "" Then
....
ElseIf TextBox2.Value = "" Then
....
ElseIf TextBox1.Value < TextBox2.Value
....
EndIf

hth,

Doug

wrote in message
oups.com...
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!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SetFocus? plh Excel Programming 1 May 1st 06 03:01 AM
setfocus Dean Reardon Excel Programming 2 December 15th 04 12:18 PM
setfocus after a msgbox simpleMod[_3_] Excel Programming 1 October 26th 04 07:25 PM
setfocus after a msgbox simpleMod[_2_] Excel Programming 1 October 26th 04 05:25 PM
setfocus after a msgbox simpleMod Excel Programming 1 October 26th 04 04:35 PM


All times are GMT +1. The time now is 05:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"