Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default TextBox Change/Exit problem

Thought I would refine and try my question again:

On my UserForm is TextBox1, it is populated during UserForm Initialization
with the value of rng(1, 7). What I would like to have happen is:

If the user changes the contents of TextBox1 then all OptionButtons (which
are located in Frame1) would be set to False and the background and border
color of Frame1 would change, giving the user a visual clue that they need
to select an OptionButton.

My problem is that when the user exits the TextBox all the OptionButtons are
set to False and the color of Frame1 is changed. I have narrowed the problem
down to the TextBox1_Exit routine because the textbox value is set to blank
and then the rewritten with the value in from sheet2. Assuming no miss
spellings I do not understand why this should be a problem. With no miss
spellings the value written back into TextBox1 should still be the same as
the value in rng(1, 7), and my If statement compares those 2 values.


Private Sub TextBox1_Change()

If TextBox1.Value < rng(1, 7) Then

OptionButton1.Value = False
OptionButton2.Value = False
OptionButton3.Value = False
OptionButton4.Value = False
OptionButton5.Value = False
OptionButton6.Value = False

Frame1.BackColor = &H80FFFF
Frame1.BorderColor = &HFF&

End If

End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Application.SpellingOptions.IgnoreCaps = False
Sheets("Sheet2").Unprotect

Sheets("Sheet2").Range("a1").Value = TextBox1.Text
Application.EnableEvents = False
Sheets("Sheet2").Range("a1").CheckSpelling
Application.EnableEvents = True
TextBox1.Text = ""
TextBox1.Text = Sheets("Sheet2").Range("a1").Value
Sheets("Sheet2").Range("a1").Value = ""

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default TextBox Change/Exit problem

apologies for my syntax errors...

but something like this should work

dim ctrl as Control
dim blnOpt
blnOpt = true

for each ctrl in Userform.Controls
if left(ctrl.name,3) = "Opt" then
if ctrl.value then
blnopt = true
end if
end if
next ctrl

if not(blnOpt) then
'Cancel form exit
end if


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default TextBox Change/Exit problem

TextBox1.Text = ""
TextBox1.Text = Sheets("Sheet2").Range("a1").Value


There is no need to clear the TextBox before assigning a new value to it...
just assign the new value (that is, eliminate the "" assignment statement).
The problem you were encountering is from that unnecessary "" assignment...
it is a change in the text for the TextBox and, as such, triggers a Change
event... your Change event sees the value in the TextBox is not equal to
rng(1,7) and, so, performs its code. Removing the

TextBox1.Text = ""

statement should solve your problem.

--
Rick (MVP - Excel)


"Patrick C. Simonds" wrote in message
...
Thought I would refine and try my question again:

On my UserForm is TextBox1, it is populated during UserForm Initialization
with the value of rng(1, 7). What I would like to have happen is:

If the user changes the contents of TextBox1 then all OptionButtons (which
are located in Frame1) would be set to False and the background and border
color of Frame1 would change, giving the user a visual clue that they need
to select an OptionButton.

My problem is that when the user exits the TextBox all the OptionButtons
are set to False and the color of Frame1 is changed. I have narrowed the
problem down to the TextBox1_Exit routine because the textbox value is set
to blank and then the rewritten with the value in from sheet2. Assuming
no miss spellings I do not understand why this should be a problem. With
no miss spellings the value written back into TextBox1 should still be the
same as the value in rng(1, 7), and my If statement compares those 2
values.


Private Sub TextBox1_Change()

If TextBox1.Value < rng(1, 7) Then

OptionButton1.Value = False
OptionButton2.Value = False
OptionButton3.Value = False
OptionButton4.Value = False
OptionButton5.Value = False
OptionButton6.Value = False

Frame1.BackColor = &H80FFFF
Frame1.BorderColor = &HFF&

End If

End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Application.SpellingOptions.IgnoreCaps = False
Sheets("Sheet2").Unprotect

Sheets("Sheet2").Range("a1").Value = TextBox1.Text
Application.EnableEvents = False
Sheets("Sheet2").Range("a1").CheckSpelling
Application.EnableEvents = True
TextBox1.Text = ""
TextBox1.Text = Sheets("Sheet2").Range("a1").Value
Sheets("Sheet2").Range("a1").Value = ""

End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default TextBox Change/Exit problem

Thanks

"Rick Rothstein" wrote in message
...
TextBox1.Text = ""
TextBox1.Text = Sheets("Sheet2").Range("a1").Value


There is no need to clear the TextBox before assigning a new value to
it... just assign the new value (that is, eliminate the "" assignment
statement). The problem you were encountering is from that unnecessary ""
assignment... it is a change in the text for the TextBox and, as such,
triggers a Change event... your Change event sees the value in the TextBox
is not equal to rng(1,7) and, so, performs its code. Removing the

TextBox1.Text = ""

statement should solve your problem.

--
Rick (MVP - Excel)


"Patrick C. Simonds" wrote in message
...
Thought I would refine and try my question again:

On my UserForm is TextBox1, it is populated during UserForm
Initialization with the value of rng(1, 7). What I would like to have
happen is:

If the user changes the contents of TextBox1 then all OptionButtons
(which are located in Frame1) would be set to False and the background
and border color of Frame1 would change, giving the user a visual clue
that they need to select an OptionButton.

My problem is that when the user exits the TextBox all the OptionButtons
are set to False and the color of Frame1 is changed. I have narrowed the
problem down to the TextBox1_Exit routine because the textbox value is
set to blank and then the rewritten with the value in from sheet2.
Assuming no miss spellings I do not understand why this should be a
problem. With no miss spellings the value written back into TextBox1
should still be the same as the value in rng(1, 7), and my If statement
compares those 2 values.


Private Sub TextBox1_Change()

If TextBox1.Value < rng(1, 7) Then

OptionButton1.Value = False
OptionButton2.Value = False
OptionButton3.Value = False
OptionButton4.Value = False
OptionButton5.Value = False
OptionButton6.Value = False

Frame1.BackColor = &H80FFFF
Frame1.BorderColor = &HFF&

End If

End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Application.SpellingOptions.IgnoreCaps = False
Sheets("Sheet2").Unprotect

Sheets("Sheet2").Range("a1").Value = TextBox1.Text
Application.EnableEvents = False
Sheets("Sheet2").Range("a1").CheckSpelling
Application.EnableEvents = True
TextBox1.Text = ""
TextBox1.Text = Sheets("Sheet2").Range("a1").Value
Sheets("Sheet2").Range("a1").Value = ""

End Sub


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
TextBox exit problem Patrick C. Simonds Excel Programming 4 August 3rd 09 01:03 AM
Pressing TAB doesn't exit TextBox Deskman Excel Programming 5 August 23rd 07 01:18 PM
Delete textbox after exit [email protected] Excel Programming 5 February 12th 07 10:43 AM
Urgent - how to run textbox exit sub? [email protected] Excel Programming 4 October 12th 06 01:43 PM
How To Get An Event To Run When I Exit A TextBox Minitman[_4_] Excel Programming 7 October 22nd 04 11:27 PM


All times are GMT +1. The time now is 02:14 PM.

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

About Us

"It's about Microsoft Excel"