Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Calling an eventprocedure

I have a userform with a textbox. How do I call the _Exit procedure
(TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) ) for this textbox
from another procedure?


I am trying to do this:
Sub Another()
If Not Test Then ' Boolean test fails
' Call the exit procedure for the textbox
Call TextBox_Exit ' Here I get an error
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
(do something clever)
End Sub

Anybody?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Calling an eventprocedure

Where is the Sub Another located?

Sub Another()
If Not Test Then ' Boolean test fails
' Call the exit procedure for the textbox
Call Userform1.TextBox_Exit ' Here I get an error
End Sub

' note: declare public if Another is outside useform module
Public Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
(do something clever)
End Sub

possibly is what you want.

Easier to put common code like this in a separate sub
Sub TakeAction()
' do something clever
end Sub

Sub Another()
If Not Test Then ' Boolean test fails
TakeAction
End if
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TakeAction
End Sub


--
Regards,
Tom Ogilvy


"Hans Petter" wrote in message
...
I have a userform with a textbox. How do I call the _Exit procedure
(TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) ) for this textbox
from another procedure?


I am trying to do this:
Sub Another()
If Not Test Then ' Boolean test fails
' Call the exit procedure for the textbox
Call TextBox_Exit ' Here I get an error
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
(do something clever)
End Sub

Anybody?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Calling an eventprocedure

Both subs are in the same userform module. My first impulse was to create a
workaround with TakeAction as you describe. I did not make it work because I
have to alter the Boolean Cancel. If user input is not valid, the Event
status must be assigned True to prevent the control from losing focus, and
in this particular case, I have to trigger the _Exit event from another sub,
not by the event itself. The Call Userform1.TextBox_Exit did not work.



When I try this: Call TextBox_Exit the error message is: Argument not
optional

To narrow it down, I understand there has to be passed over an argument to
the Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
procedure / event. I have tried to pass over a module level Cancelled, but
get the error message Type mismatch.



Is there a way I can set the event status from outside the _Exit sub/event?
Or what argument has to be passed to the _Exit sub/event? I have looked at
the RaiseEvent statement, but the _Exit sub/event is not explicitly declared
in the form module, and can not be used





Thank you for answering



Where is the Sub Another located?

Sub Another()
If Not Test Then ' Boolean test fails
' Call the exit procedure for the textbox
Call Userform1.TextBox_Exit ' Here I get an error
End Sub

' note: declare public if Another is outside useform module
Public Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
(do something clever)
End Sub

possibly is what you want.

Easier to put common code like this in a separate sub
Sub TakeAction()
' do something clever
end Sub

Sub Another()
If Not Test Then ' Boolean test fails
TakeAction
End if
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TakeAction
End Sub


--
Regards,
Tom Ogilvy


"Hans Petter" wrote in message
...
I have a userform with a textbox. How do I call the _Exit procedure
(TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) ) for this textbox
from another procedure?


I am trying to do this:
Sub Another()
If Not Test Then ' Boolean test fails
' Call the exit procedure for the textbox
Call TextBox_Exit ' Here I get an error
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
(do something clever)
End Sub

Anybody?






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Calling an eventprocedure

If the event is not being triggered by the user exiting the textbox or
whatever control it is, I am not sure setting cancel to false would have any
effect.

--
Regards,
Tom Ogilvy


"Hans Petter" wrote in message
...
Both subs are in the same userform module. My first impulse was to create

a
workaround with TakeAction as you describe. I did not make it work because

I
have to alter the Boolean Cancel. If user input is not valid, the Event
status must be assigned True to prevent the control from losing focus, and
in this particular case, I have to trigger the _Exit event from another

sub,
not by the event itself. The Call Userform1.TextBox_Exit did not work.



When I try this: Call TextBox_Exit the error message is: Argument not
optional

To narrow it down, I understand there has to be passed over an argument to
the Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
procedure / event. I have tried to pass over a module level Cancelled, but
get the error message Type mismatch.



Is there a way I can set the event status from outside the _Exit

sub/event?
Or what argument has to be passed to the _Exit sub/event? I have looked at
the RaiseEvent statement, but the _Exit sub/event is not explicitly

declared
in the form module, and can not be used





Thank you for answering



Where is the Sub Another located?

Sub Another()
If Not Test Then ' Boolean test fails
' Call the exit procedure for the textbox
Call Userform1.TextBox_Exit ' Here I get an error
End Sub

' note: declare public if Another is outside useform module
Public Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
(do something clever)
End Sub

possibly is what you want.

Easier to put common code like this in a separate sub
Sub TakeAction()
' do something clever
end Sub

Sub Another()
If Not Test Then ' Boolean test fails
TakeAction
End if
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TakeAction
End Sub


--
Regards,
Tom Ogilvy


"Hans Petter" wrote in message
...
I have a userform with a textbox. How do I call the _Exit procedure
(TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) ) for this

textbox
from another procedure?


I am trying to do this:
Sub Another()
If Not Test Then ' Boolean test fails
' Call the exit procedure for the textbox
Call TextBox_Exit ' Here I get an error
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
(do something clever)
End Sub

Anybody?








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
calling a module [email protected] Excel Discussion (Misc queries) 1 September 28th 07 04:03 PM
HELP!!!! Calling a sub from Workbook_BeforeSave RocketMan[_2_] Excel Discussion (Misc queries) 4 May 31st 07 11:47 PM
Calling an Add-In BillCPA Excel Discussion (Misc queries) 2 August 11th 05 09:32 PM
Calling Sub / Called Sub WarrenR Excel Programming 2 February 27th 04 03:11 PM
Calling SUB Peter Longstaff Excel Programming 2 February 23rd 04 08:04 PM


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