![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
I am using outlook 2007 (Latest version) with BCM and developing a small for
a home business that I run. I am trying to create a form which shows a varying number of product items on it and I need to handle the events of these product rows, e.g. when clicked, show the products details. As the number of lines on the report varies I am programmatically creating the controls on the form using the visual basic software which comes with Microsoft office 2007. The version of VB shows as “Microsoft Visual Basic 6.5” on the “About Microsoft Visual Basic” Help screen. This is part of the code used to generate the controls. Please note that the form has already been created in Project with no controls. The following code is just test code I am using to test the event handling problem. Private Sub UserForm_Initialize() Dim mycmd As Control Dim strControl As String strControl = "Forms.Label.1" Set mycmd = TestScreen.Controls.Add(strControl) mycmd.Left = 5 mycmd.Top = 5 mycmd.Width = 70 mycmd.Height = 12 mycmd.BackColor = vbRed mycmd.TextAlign = 3 mycmd.Caption = "Test Label" mycmd.Visible = True mycmd.ForeColor = vbBlack mycmd.Name = "TEST" End Sub On inspection of the code when debugging, the names of the controls (All Labels) are Label1, Label2 etc. My idea was that I would have a generic event handler to handle the events for those controls that I need events for. But here is the problem I have encountered. Initially I inserted the code Private Sub TEST_click() MsgBox ("clicked") End Sub But no events were picked up on the new control. I was thinking of adding a generic event handler but thought if the events are not being generated then this would not help either. All I need to know is how to have the created controls react to events. |
Ads |
#2
|
|||
|
|||
![]()
If you had a control variable named TEST the click event would work.
Try adding a module level variable for a Label object called myLabel: Private WithEvents myLabel As Label Then in the Initialize event, after you create the mycmd object (declare it as a Label object, not a Control object, do: Set myLabel = mycmd Then you'll have a myLabel_Click() event. -- Eric Legault [MVP - Outlook] MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007 & WSS 3.0 Application Development) President Collaborative Innovations - Try Picture Attachments Wizard 2.0 For Microsoft Outlook - - Take your SharePoint content offline - - More info: http://www.collaborativeinnovations.ca - Blog: http://blogs.officezealot.com/legault "Bunster147" wrote in message : I am using outlook 2007 (Latest version) with BCM and developing a small for a home business that I run. I am trying to create a form which shows a varying number of product items on it and I need to handle the events of these product rows, e.g. when clicked, show the products details. As the number of lines on the report varies I am programmatically creating the controls on the form using the visual basic software which comes with Microsoft office 2007. The version of VB shows as "Microsoft Visual Basic 6.5" on the "About Microsoft Visual Basic" Help screen. This is part of the code used to generate the controls. Please note that the form has already been created in Project with no controls. The following code is just test code I am using to test the event handling problem. Private Sub UserForm_Initialize() Dim mycmd As Control Dim strControl As String strControl = "Forms.Label.1" Set mycmd = TestScreen.Controls.Add(strControl) mycmd.Left = 5 mycmd.Top = 5 mycmd.Width = 70 mycmd.Height = 12 mycmd.BackColor = vbRed mycmd.TextAlign = 3 mycmd.Caption = "Test Label" mycmd.Visible = True mycmd.ForeColor = vbBlack mycmd.Name = "TEST" End Sub On inspection of the code when debugging, the names of the controls (All Labels) are Label1, Label2 etc. My idea was that I would have a generic event handler to handle the events for those controls that I need events for. But here is the problem I have encountered. Initially I inserted the code Private Sub TEST_click() MsgBox ("clicked") End Sub But no events were picked up on the new control. I was thinking of adding a generic event handler but thought if the events are not being generated then this would not help either. All I need to know is how to have the created controls react to events. |
#3
|
|||
|
|||
![]()
Thanks Eric. This seems fine if I have a single label but the number of
labels to display are unknown when the form is initialised so how do I go about declaring more than one "Private WithEvents myLabel As Label". Can I declare these on the fly, e.g. "Private withevents mylabelX as label, where X is an integer. "Eric Legault [MVP - Outlook]" wrote: If you had a control variable named TEST the click event would work. Try adding a module level variable for a Label object called myLabel: Private WithEvents myLabel As Label Then in the Initialize event, after you create the mycmd object (declare it as a Label object, not a Control object, do: Set myLabel = mycmd Then you'll have a myLabel_Click() event. -- Eric Legault [MVP - Outlook] MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007 & WSS 3.0 Application Development) President Collaborative Innovations - Try Picture Attachments Wizard 2.0 For Microsoft Outlook - - Take your SharePoint content offline - - More info: http://www.collaborativeinnovations.ca - Blog: http://blogs.officezealot.com/legault "Bunster147" wrote in message : I am using outlook 2007 (Latest version) with BCM and developing a small for a home business that I run. I am trying to create a form which shows a varying number of product items on it and I need to handle the events of these product rows, e.g. when clicked, show the products details. As the number of lines on the report varies I am programmatically creating the controls on the form using the visual basic software which comes with Microsoft office 2007. The version of VB shows as "Microsoft Visual Basic 6.5" on the "About Microsoft Visual Basic" Help screen. This is part of the code used to generate the controls. Please note that the form has already been created in Project with no controls. The following code is just test code I am using to test the event handling problem. Private Sub UserForm_Initialize() Dim mycmd As Control Dim strControl As String strControl = "Forms.Label.1" Set mycmd = TestScreen.Controls.Add(strControl) mycmd.Left = 5 mycmd.Top = 5 mycmd.Width = 70 mycmd.Height = 12 mycmd.BackColor = vbRed mycmd.TextAlign = 3 mycmd.Caption = "Test Label" mycmd.Visible = True mycmd.ForeColor = vbBlack mycmd.Name = "TEST" End Sub On inspection of the code when debugging, the names of the controls (All Labels) are Label1, Label2 etc. My idea was that I would have a generic event handler to handle the events for those controls that I need events for. But here is the problem I have encountered. Initially I inserted the code Private Sub TEST_click() MsgBox ("clicked") End Sub But no events were picked up on the new control. I was thinking of adding a generic event handler but thought if the events are not being generated then this would not help either. All I need to know is how to have the created controls react to events. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How do I stop an event from changing to recurring event automatica | WON | Outlook - Calandaring | 1 | March 2nd 08 10:42 PM |
VSTO Outlook 2003 - Issue with button event handlers | Soumitra | Add-ins for Outlook | 1 | April 20th 07 03:18 PM |
Outlook 2003, Designed Forms and button event handlers | AIK | Outlook - Using Forms | 3 | November 13th 06 02:25 PM |
Problem with CommandBarComboBox Change Event (Event fires only once) | M. Khalid Farooq | Add-ins for Outlook | 1 | October 19th 06 03:34 PM |
can a calander event to automaticaly reply during the event? How | DG at uei | Outlook - Calandaring | 1 | April 28th 06 08:45 AM |