?
Solved

Simple VB Argument question...

Posted on 2003-03-17
6
Medium Priority
?
252 Views
Last Modified: 2010-05-03
I have a quick question about writing a routine..

I have a few controls on my form...let's say a few command buttons called command1 command2 and command3.  let's say I also have a checkbox1 and optionbutton1.

I then have a label box at the bottom.  I simply want my program to display the last control that was clicked or checked.  I'm having trouble finding how to take the control as an argument and display the actual control name in the label field.  Any help is appreciated.

0
Comment
Question by:nouellette
[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
  • 4
6 Comments
 
LVL 2

Expert Comment

by:Jacamar
ID: 8153327
Here's  a quick example with 2 command buttons.  It's not very pretty, but it'll do what you want.

Private Sub Command1_Click()
Label1.Caption = Command1.Name
End Sub
Private Sub Command2_Click()
Label1.Caption = Command2.Name
End Sub
0
 
LVL 18

Accepted Solution

by:
deighton earned 150 total points
ID: 8153341
Private Sub Command1_Click()
display Me.ActiveControl

End Sub

Private Sub Command2_Click()
display Me.ActiveControl

End Sub

Sub display(cntX As Control)

    Label1.Caption = cntX.Name


End Sub
0
 
LVL 3

Author Comment

by:nouellette
ID: 8153487
jacamar...i can definitely do that...but thats getting around what i really need this to do...and thats to actually pass the control's name through to the label box.  basically to write a routine that takes a control as an argument and displays it in the label box.

i believe this is what deightons code is doing but im not 100% sure.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:nouellette
ID: 8153592
Deighton...works great...how can I also get the control TYPE for the "ActiveControl"?  cntX.Name pulls it's name just fine...but what could I use to also pull the actual type...meaning I could says "you selected " & cntX.Name & "Which is of type " &    

After Which is of type...I want to be able to pass the control type too...command button, option button, whatever the control object is...I would like to be able to pull that as well.
0
 
LVL 3

Author Comment

by:nouellette
ID: 8153606
Deighton...works great...how can I also get the control TYPE for the "ActiveControl"?  cntX.Name pulls it's name just fine...but what could I use to also pull the actual type...meaning I could says "you selected " & cntX.Name & "Which is of type " &    

After Which is of type...I want to be able to pass the control type too...command button, option button, whatever the control object is...I would like to be able to pull that as well.
0
 
LVL 3

Author Comment

by:nouellette
ID: 8153671
Nevermind...got it...just changed DISPLAY to NotifyControlType and pulled the control type as well as the control name.  Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

752 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