Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default setfocus on user form

In a user form I want to ensure that textbox7 contains either YES or NO when
the form is completed. If there is anything else in textbox7, I want the
form shown again with the focus on textbox7 and its contents highlighted.
The following does not set the focus or highlight the contents but doesn't
let me exit the form until I have yes or no in the textbox. Can someone tell
me what is missing please?


Private Sub CommandButton1_Click()
Dim test As Boolean

again1:
test = UCase(TextBox7.Value) = "YES" Or UCase(TextBox7.Value) = "NO"
If Not test Then
normLog10.Hide
MsgBox (TextBox7.Value & " is not acceptable, must be yes or no" &
vbCrLf & vbCrLf & _
" Try again")
normLog10.Show
TextBox7.SetFocus
TextBox7.SelStart = 0
TextBox7.SelLength = 100
GoTo again1:
End If
end sub

Thanks
Chris


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default setfocus on user form

Chris,

Try this, I haven't tested it.

normLog10.Show

With TextBox7
.SelStart = 0
.SelLength = Len(.Text)
End With

GoTo again1:



regards
Neil


"inquirer" wrote in message
...
In a user form I want to ensure that textbox7 contains either YES or NO
when the form is completed. If there is anything else in textbox7, I want
the form shown again with the focus on textbox7 and its contents
highlighted.
The following does not set the focus or highlight the contents but doesn't
let me exit the form until I have yes or no in the textbox. Can someone
tell me what is missing please?


Private Sub CommandButton1_Click()
Dim test As Boolean

again1:
test = UCase(TextBox7.Value) = "YES" Or UCase(TextBox7.Value) = "NO"
If Not test Then
normLog10.Hide
MsgBox (TextBox7.Value & " is not acceptable, must be yes or no" &
vbCrLf & vbCrLf & _
" Try again")
normLog10.Show
TextBox7.SetFocus
TextBox7.SelStart = 0
TextBox7.SelLength = 100
GoTo again1:
End If
end sub

Thanks
Chris



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default setfocus on user form

Hi,
Moved .show line.

Private Sub CommandButton1_Click()
Dim test As Boolean

again1:
test = UCase(TextBox7.Value) = "YES" Or UCase(TextBox7.Value) = "NO"
If Not test Then
normLog10.Hide
MsgBox (TextBox7.Value & " is not acceptable, must be yes or no" &
vbCrLf & vbCrLf & _
" Try again")

TextBox7.SetFocus
TextBox7.SelStart = 0
TextBox7.SelLength = 100
normLog10.Show <=========== Moved!
GoTo again1:
End If
end sub


"inquirer" wrote:

In a user form I want to ensure that textbox7 contains either YES or NO when
the form is completed. If there is anything else in textbox7, I want the
form shown again with the focus on textbox7 and its contents highlighted.
The following does not set the focus or highlight the contents but doesn't
let me exit the form until I have yes or no in the textbox. Can someone tell
me what is missing please?


Private Sub CommandButton1_Click()
Dim test As Boolean

again1:
test = UCase(TextBox7.Value) = "YES" Or UCase(TextBox7.Value) = "NO"
If Not test Then
normLog10.Hide
MsgBox (TextBox7.Value & " is not acceptable, must be yes or no" &
vbCrLf & vbCrLf & _
" Try again")
normLog10.Show
TextBox7.SetFocus
TextBox7.SelStart = 0
TextBox7.SelLength = 100
GoTo again1:
End If
end sub

Thanks
Chris



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default setfocus on user form

This works for me

Private Sub CommandButton1_Click()
Dim test As Boolean

With TextBox7
test = UCase(.Value) = "YES" Or UCase(.Value) = "NO"
If Not test Then
MsgBox (.Value & " is not acceptable, must be yes or no" & _
vbCrLf & vbCrLf & " Try again")
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End If
End With
End Sub

--
HTH

Bob Phillips

"inquirer" wrote in message
...
In a user form I want to ensure that textbox7 contains either YES or NO

when
the form is completed. If there is anything else in textbox7, I want the
form shown again with the focus on textbox7 and its contents highlighted.
The following does not set the focus or highlight the contents but doesn't
let me exit the form until I have yes or no in the textbox. Can someone

tell
me what is missing please?


Private Sub CommandButton1_Click()
Dim test As Boolean

again1:
test = UCase(TextBox7.Value) = "YES" Or UCase(TextBox7.Value) = "NO"
If Not test Then
normLog10.Hide
MsgBox (TextBox7.Value & " is not acceptable, must be yes or no" &
vbCrLf & vbCrLf & _
" Try again")
normLog10.Show
TextBox7.SetFocus
TextBox7.SelStart = 0
TextBox7.SelLength = 100
GoTo again1:
End If
end sub

Thanks
Chris




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default setfocus on user form

Hi Chris

Allow me to say that a textbox is perhaps the worst choice of control for a
forced yes-no-response. You should use either a combobox set to List style,
or two optionbuttons (aka radio buttons).

HTH. Best wishes Harald

"inquirer" skrev i melding
...
In a user form I want to ensure that textbox7 contains either YES or NO

when
the form is completed. If there is anything else in textbox7, I want the
form shown again with the focus on textbox7 and its contents highlighted.
The following does not set the focus or highlight the contents but doesn't
let me exit the form until I have yes or no in the textbox. Can someone

tell
me what is missing please?


Private Sub CommandButton1_Click()
Dim test As Boolean

again1:
test = UCase(TextBox7.Value) = "YES" Or UCase(TextBox7.Value) = "NO"
If Not test Then
normLog10.Hide
MsgBox (TextBox7.Value & " is not acceptable, must be yes or no" &
vbCrLf & vbCrLf & _
" Try again")
normLog10.Show
TextBox7.SetFocus
TextBox7.SelStart = 0
TextBox7.SelLength = 100
GoTo again1:
End If
end sub

Thanks
Chris






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default setfocus on user form

Or even a single checkbox.

Harald Staff wrote:

Hi Chris

Allow me to say that a textbox is perhaps the worst choice of control for a
forced yes-no-response. You should use either a combobox set to List style,
or two optionbuttons (aka radio buttons).

HTH. Best wishes Harald

"inquirer" skrev i melding
...
In a user form I want to ensure that textbox7 contains either YES or NO

when
the form is completed. If there is anything else in textbox7, I want the
form shown again with the focus on textbox7 and its contents highlighted.
The following does not set the focus or highlight the contents but doesn't
let me exit the form until I have yes or no in the textbox. Can someone

tell
me what is missing please?


Private Sub CommandButton1_Click()
Dim test As Boolean

again1:
test = UCase(TextBox7.Value) = "YES" Or UCase(TextBox7.Value) = "NO"
If Not test Then
normLog10.Hide
MsgBox (TextBox7.Value & " is not acceptable, must be yes or no" &
vbCrLf & vbCrLf & _
" Try again")
normLog10.Show
TextBox7.SetFocus
TextBox7.SelStart = 0
TextBox7.SelLength = 100
GoTo again1:
End If
end sub

Thanks
Chris



--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default setfocus on user form

Yes

Best wishes Harald

"Dave Peterson" skrev i melding
...
Or even a single checkbox.

Harald Staff wrote:

Hi Chris

Allow me to say that a textbox is perhaps the worst choice of control

for a
forced yes-no-response. You should use either a combobox set to List

style,
or two optionbuttons (aka radio buttons).

HTH. Best wishes Harald



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default setfocus on user form

Mnay thanks for your help. Moving the .show line fixed my problem. I will
look into replacing the textbox with an option button or check box as well.
Thanks again
Chris

"Toppers" wrote in message
...
Hi,
Moved .show line.

Private Sub CommandButton1_Click()
Dim test As Boolean

again1:
test = UCase(TextBox7.Value) = "YES" Or UCase(TextBox7.Value) = "NO"
If Not test Then
normLog10.Hide
MsgBox (TextBox7.Value & " is not acceptable, must be yes or no" &
vbCrLf & vbCrLf & _
" Try again")

TextBox7.SetFocus
TextBox7.SelStart = 0
TextBox7.SelLength = 100
normLog10.Show <=========== Moved!
GoTo again1:
End If
end sub


"inquirer" wrote:

In a user form I want to ensure that textbox7 contains either YES or NO
when
the form is completed. If there is anything else in textbox7, I want the
form shown again with the focus on textbox7 and its contents highlighted.
The following does not set the focus or highlight the contents but
doesn't
let me exit the form until I have yes or no in the textbox. Can someone
tell
me what is missing please?


Private Sub CommandButton1_Click()
Dim test As Boolean

again1:
test = UCase(TextBox7.Value) = "YES" Or UCase(TextBox7.Value) = "NO"
If Not test Then
normLog10.Hide
MsgBox (TextBox7.Value & " is not acceptable, must be yes or no" &
vbCrLf & vbCrLf & _
" Try again")
normLog10.Show
TextBox7.SetFocus
TextBox7.SelStart = 0
TextBox7.SelLength = 100
GoTo again1:
End If
end sub

Thanks
Chris





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
How to: User Form to assign a user defined range to a macro variab TrevTrav Excel Programming 1 March 22nd 05 07:57 PM
setfocus on multipage tab form gives error message Cheryl Excel Programming 3 July 28th 04 03:07 PM
SetFocus in user form John Tjia Excel Programming 6 February 2nd 04 03:05 PM
I am looking to see if anybody has an equivalant user form to Outlooks CONTACT form BruceJ[_2_] Excel Programming 2 October 15th 03 05:28 PM


All times are GMT +1. The time now is 03:51 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"