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() problem

On my UserForm is TextBox1, which if a user makes a change to the TextBox I
want the value of some OptionButtons set to false. That in its self is easy
enough, using the TextBox1_Change routine below. My problem is that during
UserForm Initialization TextBox1 is populated with the following code:

TextBox1.Value = rng(1, 7).Text

Unfortunately the TextBox1_Change routine sees that as a change and sets
all OptionButtons to False. Any suggestions?

Private Sub TextBox1_Change()

Me.TextBox1 = UCase(Me.TextBox1.Text)

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

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default TextBox_Change() problem

The simple way to avoid this is to declare a UserForm-wide 'global' Boolean
variable (declare it in the General/Declarations section of the code window,
outside of any declared procedures), check it for being False in the
TextBox's Change event (exiting the Sub if it is) and then setting it to
True at the end of the UserForm's Initialize event so it won't interfere
with the normal operation of the TextBox's Change event. Here is the
general structure of what I am talking about...

Dim Initialized As Boolean

Private Sub TextBox1_Change()
If Not Initialized Then Exit Sub
'
' Your change event code goes here
'
End Sub

Private Sub UserForm_Initialize()
'
' Your UserForm's initialing code goes here
'
Initialized = True
End Sub

--
Rick (MVP - Excel)


"Patrick C. Simonds" wrote in message
...
On my UserForm is TextBox1, which if a user makes a change to the TextBox
I want the value of some OptionButtons set to false. That in its self is
easy enough, using the TextBox1_Change routine below. My problem is that
during UserForm Initialization TextBox1 is populated with the following
code:

TextBox1.Value = rng(1, 7).Text

Unfortunately the TextBox1_Change routine sees that as a change and sets
all OptionButtons to False. Any suggestions?

Private Sub TextBox1_Change()

Me.TextBox1 = UCase(Me.TextBox1.Text)

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

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default TextBox_Change() problem

when I encounter similar problem I just place a one liner in the change event
crude but seems to work!

Private Sub TextBox1_Change()

If Me.Visible = False Then Exit Sub

Me.TextBox1 = UCase(Me.TextBox1.Text)

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

End Sub
--
jb


"Patrick C. Simonds" wrote:

On my UserForm is TextBox1, which if a user makes a change to the TextBox I
want the value of some OptionButtons set to false. That in its self is easy
enough, using the TextBox1_Change routine below. My problem is that during
UserForm Initialization TextBox1 is populated with the following code:

TextBox1.Value = rng(1, 7).Text

Unfortunately the TextBox1_Change routine sees that as a change and sets
all OptionButtons to False. Any suggestions?

Private Sub TextBox1_Change()

Me.TextBox1 = UCase(Me.TextBox1.Text)

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

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default TextBox_Change() problem

I'd use a variable at the top of that userform module:

Option Explicit
Dim BlkProc as boolean
Private Sub Userform_Initialize()

blkproc = true
me.textbox1.value = "hi there"
blkproc = false

End Sub
Private Sub TextBox1_Change()

if blkproc = true then exit sub

blkproc = true
Me.TextBox1.value = UCase(Me.TextBox1.Text)
blkproc = false

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

End Sub

I like this because I can use the same idea whenever I change that
textbox--including making it uppercase!


"Patrick C. Simonds" wrote:

On my UserForm is TextBox1, which if a user makes a change to the TextBox I
want the value of some OptionButtons set to false. That in its self is easy
enough, using the TextBox1_Change routine below. My problem is that during
UserForm Initialization TextBox1 is populated with the following code:

TextBox1.Value = rng(1, 7).Text

Unfortunately the TextBox1_Change routine sees that as a change and sets
all OptionButtons to False. Any suggestions?

Private Sub TextBox1_Change()

Me.TextBox1 = UCase(Me.TextBox1.Text)

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

End Sub


--

Dave Peterson
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
Colon at the end of excel file name(ex: problem.xls:1, problem.xls financeguy New Users to Excel 2 January 15th 10 01:15 AM
suspend processing for TextBox_Change events when initializing a f drhalter Excel Programming 3 February 6th 08 01:17 PM
TextBox_Change a little premature! Post Tenebras Lux Excel Programming 4 September 4th 06 10:03 AM
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? OCI Excel Programming 0 May 16th 04 10:40 PM


All times are GMT +1. The time now is 10:16 AM.

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"