PC Review


Reply
Thread Tools Rate Thread

Change Event duplicating action

 
 
LuisE
Guest
Posts: n/a
 
      26th Dec 2007
I have a textbox that is getting a range address.
If the total of columns or row is higher than 5 I want to show an MsgBox and
clear its contents. It works fine but when the value becomes "" the change
event is obviously triggered but in this case since tha value is nothing it
still validates the number of columns/ros as higher than 5 and prompts the
message again

Private Sub TextBox1_Change()

If Range(TextBox1.Value).Columns.Count > 5 Or
Range(TextBox1.Value).Rows.Count > 5 Then

MsgBox "Limit of 5 columns and rows"
TextBox1.Value = ""

Else
Call AnotherMacro

End If
End Sub

I tried the afterupdate event but it doesn't work.

Thanks in advance.
 
Reply With Quote
 
 
 
 
Darren Hill
Guest
Posts: n/a
 
      26th Dec 2007
Does this work:

Private Sub TextBox1_Change()
if TextBox1.Value = "" then exit sub

If Range(TextBox1.Value).Columns.Count > 5 Or
Range(TextBox1.Value).Rows.Count > 5 Then

MsgBox "Limit of 5 columns and rows"
TextBox1.Value = ""

Else
Call AnotherMacro

End If
End Sub

LuisE wrote:
> I have a textbox that is getting a range address.
> If the total of columns or row is higher than 5 I want to show an MsgBox and
> clear its contents. It works fine but when the value becomes "" the change
> event is obviously triggered but in this case since tha value is nothing it
> still validates the number of columns/ros as higher than 5 and prompts the
> message again
>
> Private Sub TextBox1_Change()
>
> If Range(TextBox1.Value).Columns.Count > 5 Or
> Range(TextBox1.Value).Rows.Count > 5 Then
>
> MsgBox "Limit of 5 columns and rows"
> TextBox1.Value = ""
>
> Else
> Call AnotherMacro
>
> End If
> End Sub
>
> I tried the afterupdate event but it doesn't work.
>
> Thanks in advance.

 
Reply With Quote
 
LuisE
Guest
Posts: n/a
 
      26th Dec 2007
Darren, thanks for the prompt response
I found another approach that works turning the Application.EnableEvents =
False




Private Sub TextBox1_Change()
On Error GoTo XIT
Application.EnableEvents = False

If Range(TextBox1.Value).Columns.Count > 5 Or
Range(TextBox1.Value).Rows.Count > 5 Then

MsgBox "Limit of 5 columns and rows"
TextBox1.Value = ""

Else
Call AnotherMacro

End If

XIT:
Application.EnableEvents = True

End Sub

> LuisE wrote:
> > I have a textbox that is getting a range address.
> > If the total of columns or row is higher than 5 I want to show an MsgBox and
> > clear its contents. It works fine but when the value becomes "" the change
> > event is obviously triggered but in this case since tha value is nothing it
> > still validates the number of columns/ros as higher than 5 and prompts the
> > message again
> >
> > Private Sub TextBox1_Change()
> >
> > If Range(TextBox1.Value).Columns.Count > 5 Or
> > Range(TextBox1.Value).Rows.Count > 5 Then
> >
> > MsgBox "Limit of 5 columns and rows"
> > TextBox1.Value = ""
> >
> > Else
> > Call AnotherMacro
> >
> > End If
> > End Sub
> >
> > I tried the afterupdate event but it doesn't work.
> >
> > Thanks in advance.

>

 
Reply With Quote
 
LuisE
Guest
Posts: n/a
 
      26th Dec 2007
After all it worked better than the other approach because I had references
to other objects. Thank you

"Darren Hill" wrote:

> Does this work:
>
> Private Sub TextBox1_Change()
> if TextBox1.Value = "" then exit sub
>
> If Range(TextBox1.Value).Columns.Count > 5 Or
> Range(TextBox1.Value).Rows.Count > 5 Then
>
> MsgBox "Limit of 5 columns and rows"
> TextBox1.Value = ""
>
> Else
> Call AnotherMacro
>
> End If
> End Sub
>
> LuisE wrote:
> > I have a textbox that is getting a range address.
> > If the total of columns or row is higher than 5 I want to show an MsgBox and
> > clear its contents. It works fine but when the value becomes "" the change
> > event is obviously triggered but in this case since tha value is nothing it
> > still validates the number of columns/ros as higher than 5 and prompts the
> > message again
> >
> > Private Sub TextBox1_Change()
> >
> > If Range(TextBox1.Value).Columns.Count > 5 Or
> > Range(TextBox1.Value).Rows.Count > 5 Then
> >
> > MsgBox "Limit of 5 columns and rows"
> > TextBox1.Value = ""
> >
> > Else
> > Call AnotherMacro
> >
> > End If
> > End Sub
> >
> > I tried the afterupdate event but it doesn't work.
> >
> > Thanks in advance.

>

 
Reply With Quote
 
Darren Hill
Guest
Posts: n/a
 
      26th Dec 2007
Glad to help

Darren

LuisE wrote:
> After all it worked better than the other approach because I had references
> to other objects. Thank you
>
> "Darren Hill" wrote:
>
>> Does this work:
>>
>> Private Sub TextBox1_Change()
>> if TextBox1.Value = "" then exit sub
>>
>> If Range(TextBox1.Value).Columns.Count > 5 Or
>> Range(TextBox1.Value).Rows.Count > 5 Then
>>
>> MsgBox "Limit of 5 columns and rows"
>> TextBox1.Value = ""
>>
>> Else
>> Call AnotherMacro
>>
>> End If
>> End Sub
>>
>> LuisE wrote:
>>> I have a textbox that is getting a range address.
>>> If the total of columns or row is higher than 5 I want to show an MsgBox and
>>> clear its contents. It works fine but when the value becomes "" the change
>>> event is obviously triggered but in this case since tha value is nothing it
>>> still validates the number of columns/ros as higher than 5 and prompts the
>>> message again
>>>
>>> Private Sub TextBox1_Change()
>>>
>>> If Range(TextBox1.Value).Columns.Count > 5 Or
>>> Range(TextBox1.Value).Rows.Count > 5 Then
>>>
>>> MsgBox "Limit of 5 columns and rows"
>>> TextBox1.Value = ""
>>>
>>> Else
>>> Call AnotherMacro
>>>
>>> End If
>>> End Sub
>>>
>>> I tried the afterupdate event but it doesn't work.
>>>
>>> Thanks in advance.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Change the Shutdown Action To Reboot Action in statr menu shatztal Windows XP General 12 13th Sep 2009 06:50 PM
Worksheet Change Event Refuses to Action Darren Microsoft Excel Programming 3 20th Jun 2009 09:52 AM
Action Event, CheckBox, Add Row and Textbox =?Utf-8?B?Unlhbg==?= Microsoft Excel Misc 2 17th Jul 2007 02:32 PM
Cancel event action Boni Microsoft C# .NET 2 6th Jun 2005 09:46 AM
Run an event when the ESC key or undo action is trigged And Microsoft Access 3 14th Jan 2005 04:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:24 PM.