[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Using control created at runtime

Posted on 1998-10-14
3
Medium Priority
?
145 Views
Last Modified: 2010-04-30
I have a form in VBA which has a command button. Every time I click it I create a new command button.
How do I attach an event to the new buttons, so that when I click any of themm, I can run some code?

The code so far is as follows:-

Dim Mycmd As Control

Private Sub CommandButton1_Click()
Static i&

i& = i& + 1
Set Mycmd = Controls.Add("Forms.CommandButton.1")
With Mycmd
  .Left = 12
  .Top = 25 * i& + 25
  .Caption = .Name
End With

End Sub
0
Comment
Question by:broadbent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
traygreen earned 100 total points
ID: 1439901
Create the button as the 0 item in a control array
eg name = cmdTest
   item = 0

replace your set code with
   iCurrentCont = cmdTest.count -1
   Load cmdTest(iCurrentCont)
   cmdTest(iCurrentControl).left = .......

This will allow all of the new controls to access the evnets set up for the intital command button.  You could build the logic into the event (say click) to account for there being more than one control element
0
 
LVL 5

Expert Comment

by:AnswerTheMan
ID: 1439902
traygreen's answer is correct but he did not explain it well.
if i was in a situation that i know nothing about it - i would not understand a thing from his answer.
traygreen,  if u AnswerTheMan - do it from your heart.
0
 
LVL 4

Author Comment

by:broadbent
ID: 1439903
sorry , but controls in VBA can't be indexed!
Thats the problem
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question