|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
WithEvents code in module cannot change textbox on main formI'm using Visual Basic 2005 Express I have a form - Form1 - with a control called txtStatusBox I have a module attached to the solution for storing some other code. This links to an Outlook MAPI folder (variable ContItems), that waits for new items to arrive. When a new message is delivered, the event is fired. However, when it tries to change the text in a textbox on Form1, the box remains unchanged: Private Sub ConItems_ItemAdd(ByVal Item As Object) Handles ConItems.ItemAdd MyForm.txtStatusBox.Text="text has changed" End Sub I do know that the event fires because if i put a breakpoint on the line, it breaks when a message arrives. If I call another sub that lies within the same module, such as Public Sub ChangeTextOnForm() MyForm.txtStatusBox.Text="text has changed" End Sub then it DOES work. So, both subs are in the same module, and have the same code, and neither reports an error. But for some reason, the code does not work for the even procudure. If I try to call the first sub from within the second, then it still doesn't work. It's like the event code is running in a lower security context than other code in the module. Can anyone explain this please? it's driving me nuts! thanks joel See if this helps:
Private Sub ConItems_ItemAdd(ByVal Item As Object) Handles ConItems.ItemAdd MyForm.txtStatusBox.Text="text has changed" MyForm.txtStatusBox.Refresh() End Sub J***@GlobalF.com wrote: Show quoteHide quote > When a new message is delivered, the event is fired. However, when it tries to change > the text in a textbox on Form1, the box remains unchanged: > I do know that the event fires because if i put a breakpoint on the > line, it breaks when a message arrives. No tried that unfortunately.
It seems to be a security thing. can code in one module be restricted from editing textboxes on another form? the event is not fired by any user input but by an email arriving in the inbox, so maybe the procedure runs under an anonymous user account? You may need a factory class...
Create a class with a shared property referring to the form instance whose textbox you're trying to manipulate via the module. You'll need to "store" the form instance in the class when the form opens. Do a search on "global variables" in help. As they do not exist in VB2005, I thing you'll get an article or two indicating how to do this... -- Show quoteHide quoteGrumpy Aero Guy <Jo***@GlobalF.com> wrote in message news:1150297076.360777.166940@f6g2000cwb.googlegroups.com... > This is really weird... > I'm using Visual Basic 2005 Express > I have a form - Form1 - with a control called txtStatusBox > > I have a module attached to the solution for storing some other code. > This links to an Outlook MAPI folder (variable ContItems), that waits > for new items to arrive. > When a new message is delivered, the event is fired. > However, when it tries to change the text in a textbox on Form1, the > box remains unchanged: > > Private Sub ConItems_ItemAdd(ByVal Item As Object) Handles > ConItems.ItemAdd > MyForm.txtStatusBox.Text="text has changed" > End Sub > > I do know that the event fires because if i put a breakpoint on the > line, it breaks when a message arrives. > > If I call another sub that lies within the same module, such as > > Public Sub ChangeTextOnForm() > MyForm.txtStatusBox.Text="text has changed" > End Sub > > then it DOES work. So, both subs are in the same module, and have the > same code, and neither reports an error. But for some reason, the code > does not work for the even procudure. > If I try to call the first sub from within the second, then it still > doesn't work. It's like the event code is running in a lower security > context than other code in the module. > > Can anyone explain this please? it's driving me nuts! > > > thanks > joel >
Undefined function 'InStrRev' in expression.
Is this Possible ? The big Debate on DoEvents Array Problems - still cant get something set up right. Dll fails to register Click and Double click events are not fired in listview component in VB.NET How can I get Windows user, password and domain? Reading XML file getting error How to override only Get or only Set? where shoule store the questions and answers |
|||||||||||||||||||||||