Userform Command Button

In a Userform, I have multiple command buttons.  For example:

D1_Click
D2_Click

Depending on another event that occurs, I want to calculate in code the 
button name that I will be triggering the click event and then trigger the 
event.

For example Application.Run "D" & i & "_Click"

with i being the value of 1 or 2.

Application.Run doesn't appear to work in the Userform.

Thanks

Steve
0
Utf
2/26/2010 8:32:03 PM
excel.programming 6508 articles. 2 followers. Follow

3 Replies
1286 Views

Similar Articles

[PageSpeed] 57

Maybe it's because most subroutines in a userform module
are "Private"???   Have you tried changing the "Private"
prefix to "Public" for the D?_Click subroutines??  Maybe
that might fix it......

Also, im not entirely sure if changing routines from Private
to Public is a good idea for userform subroutines.  Maybe
you can place your D?_Click code in a normal module
instead???


"sarndt" <sarndt@discussions.microsoft.com> wrote in message 
news:F96922B7-B52E-4530-B053-1148FB6E9B55@microsoft.com...
> In a Userform, I have multiple command buttons.  For example:
>
> D1_Click
> D2_Click
>
> Depending on another event that occurs, I want to calculate in code the
> button name that I will be triggering the click event and then trigger the
> event.
>
> For example Application.Run "D" & i & "_Click"
>
> with i being the value of 1 or 2.
>
> Application.Run doesn't appear to work in the Userform.
>
> Thanks
>
> Steve 

0
Robert
2/26/2010 9:03:33 PM
I tried changing it to Public and that didn't work.  And Application.Run only 
appears to work with a macro.

"Robert Crandal" wrote:

> Maybe it's because most subroutines in a userform module
> are "Private"???   Have you tried changing the "Private"
> prefix to "Public" for the D?_Click subroutines??  Maybe
> that might fix it......
> 
> Also, im not entirely sure if changing routines from Private
> to Public is a good idea for userform subroutines.  Maybe
> you can place your D?_Click code in a normal module
> instead???
> 
> 
> "sarndt" <sarndt@discussions.microsoft.com> wrote in message 
> news:F96922B7-B52E-4530-B053-1148FB6E9B55@microsoft.com...
> > In a Userform, I have multiple command buttons.  For example:
> >
> > D1_Click
> > D2_Click
> >
> > Depending on another event that occurs, I want to calculate in code the
> > button name that I will be triggering the click event and then trigger the
> > event.
> >
> > For example Application.Run "D" & i & "_Click"
> >
> > with i being the value of 1 or 2.
> >
> > Application.Run doesn't appear to work in the Userform.
> >
> > Thanks
> >
> > Steve 
> 
> .
> 
0
Utf
2/26/2010 10:10:01 PM
Use CallByName. E.g.,

Dim S As String 
S = "CommandButton1_Click"
CallByName UserForm1, S, VbMethod

The CommandButton1_Click must be declared as Public.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
	Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Fri, 26 Feb 2010 12:32:03 -0800, sarndt
<sarndt@discussions.microsoft.com> wrote:

>In a Userform, I have multiple command buttons.  For example:
>
>D1_Click
>D2_Click
>
>Depending on another event that occurs, I want to calculate in code the 
>button name that I will be triggering the click event and then trigger the 
>event.
>
>For example Application.Run "D" & i & "_Click"
>
>with i being the value of 1 or 2.
>
>Application.Run doesn't appear to work in the Userform.
>
>Thanks
>
>Steve
0
Chip
2/26/2010 10:33:33 PM
Reply:

Similar Artilces:

News command does not appear in the list of available commands for the Go category.
I Just ran into this problem. It seems identical to the issue posted at http://www.winnetmag.com/MicrosoftExchangeOutlook/Article/ArticleID/43544/43544.html "I recently followed the Microsoft Office Online Help instructions for customizing menus to add the News command to my Office Outlook 2003 Go menu. The task was successful, and I could start Outlook Express's newsreader from Outlook's newly added News command. However, after Outlook Express started, the News command disappeared from the Outlook Go menu. "In an attempt to determine what was causing the problem, I m...

How to Send Outlook Message from command Line
I have a simple txt file that I would like to send via outlook.exe using line commands. I plan to run a findstr command in a DOS script that is kicked off by the Windows Scheduler and if it finds something I want to send the output via outlook. Can someone give me an example of sending a file to a person using a line command? I don't know what switches might be available to me and outlook.exe /? and help outlook do not provide any information. Thanks ...

How to disable the close button of a view in MDI
Hi All, In my MDI application I have 4 views in which one view is the most important one and should not be closed by the user, but the remainig views should have the facility of close button. If I handle CChildFrame::OnSysCommand(UINT nID, LPARAM lParam) it will disable the close button of all the views . Can someone please help me with a solution? Regards, JLD You could keep track of the special ChildFrame which you want to always keep by doing like this: int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1) return -1; if(g_MyS...

Creating a userform?
I would like to enter data to a speadsheet with a userform. I want enter the data in a form that will automatically insert the data to the correct cells in my spreadsheet. And then allow me to enter new data on the next line below. Is this possible? I have just put up a file for you at:- http://www.pierrefondes.com/ It is item number 42 towards the top of my home page. In here I have tried to explain, as clearly as possible, what you need to do to set up and use a Form in EXCEL 2007. There is a simple worked example for you to work through if you want to. Please d...

No Send Button #3
I have decided I want to start using Outlook 2003 (after using Outlook Express for years). I have the Office 2003 Professional Edition, which includes Outlook. I successfully imported my address book and email folders from OE. I went through the steps of setting up an email account, tested it, says it was successful; but I never did get the test email in Outlook. (I opened OE and the test emails came in there just fine) I tried to compose an email, and noticed there is no "send" button. Also, when I go to File, New, the option of New Message is not there at all, the first th...

MSDaRT 6.0 ERD Commander Not Accepting Incoming Connections
I can't figure out how to get ERD Commander boot environment that comes with MSDaRT 6.0 to accept incoming TCP connections. I've used Sysinternals psservice to stop the firewall to no avail. I've even stopped the Base Filtering Engine and all svchost processes and services.exe... I tried to modify the firewall but netsh firewall context isn't present. Routing table looks fine... I'm beginning to dig around in the tcpip key in HKLM/SYSTEM/Current Control Set/ Services. I really want to be able to boot MSDaRT and run servers such as VNC, FTP, etc. Anyone have...

Right mouse button doesn't work
Hi there, I have a problem with right button of the mouse. When I click on right button in order to get floating context dialog, no action occured. I have to use special Windows button on my clipboard, but it is annoying. Does anybody know the solution ? Thanks Satucha -- satucha ------------------------------------------------------------------------ satucha's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=26621 View this thread: http://www.excelforum.com/showthread.php?threadid=479394 Try running this command in the immediate window of the VBE (Alt/F11 ...

Keyboard arrow buttons no longer work in excel
I can no longer use the arrow buttons to move around my excel worksheet (to change the active cell). When I click on the up or down arrows th sheet itself moves up or down, however the active cell remains th same. I have looked in the "Tools" - "Options" area to see if I nee to set or reset something but cannot find anything. I can't imagine what happened (except I do have a few feline friend who use my pc when I'm not looking!) I would appreciate any input ... Thanks Bernadett -- bcp196 ----------------------------------------------------------------------- ...

Open Userforms from a Dropdown list
Hello, and thanks for the help, I have several userforms and would like to place the names of the forms into a dropdown list to select the form i wish to use is this possible. again thanks ...

opening a userform from a userform
Is there a way to open and use a userform from another userform? I am using userforms for data entry and would like the option to open a second form whilst entering data into a form Can anyone help? [excel 2003] Just Show it. Call is like this... UserForm2.Show or like this... UserForm2.Show vbModeless depending on whether you want UserForm2 to be modal or non-modal. Remember to change my example UserForm name from UserForm2 to whatever the name your second UserForm is. -- Rick (MVP - Excel) "Roger on Excel" <RogeronExcel@discussions.microsof...

Cannot Use AD Commands in Command Prompt
I have a very aggravating problem where whenever I enter an AD command at the DOS prompt, I lose my AD connection, and have to lock, and unlock the client in order to use any AD resources, including the MMC The message in the command prompt is "The system detected a possible attempt to compromise security. Please ensure that you can contact the server that authenticated you." Any ideas on why a command at the command prompt would disconnect me? I would look in the event log on both the dc you are connecting to and your local client in which you are connecting t...

passwords - userforms
[Excel 2003] I have a spreadsheet which uses forms to enter and display data. The Spreadsheet uses a main page form "frmDashboard" from which other userforms are activated using command buttons. The form frmDashoboard remains open in the background as a desktop while the user activates the other forms. I am looking at various methods to password protect the opening of other forms from the main useform frmDashboard and I use the following code to do this: Private Sub CommandButton1_Click() Dim i_pwd As String i_pwd = InputBox("Please Enter Password&q...

How I open Microsoft Dynamics GP through Command Prompt
I want to Open Microsoft Dynamics GP through command prompt with out entering user name password. I provide user name n password in the batch file. My qustion is that if I open GP through command prompt I dont want to enter password and i dont want to select company . I want that home page will appare directly. dont ask y i require this but i need this . If u please help me to finding out this. Download Microsoft's documentation on the Integration Manager and look at the last chapter. It discusses creating a macro to run on launch that will log a user in and select a company, ta...

userform
hello everybody, is it possible to see the content of a cell (i.e. worksheet 1 cell y32) (and all it's changes) in a userform (which is also used to input data) while it is still open? Hi You will probably need some code for that, like Label1.Caption = Sheets(1).Range("Y32").Text trigged by some relevant events, like the Exit events of your input boxes. -- HTH. Best wishes Harald Followup to newsgroup only please. "Mauro" <mlauro@fastwebnet.it> wrote in message news:WlKQb.4922$VS6.4580@tornado.fastwebnet.it... > hello everybody, is it possible to see the ...

Excel, button for macro
Hello, I have a protected (real password... not just protection wihout password..) template with a button who star a macro. The macro change some informations, use the filters and print the result. When I push the button, the system ask for the password. Do you have ideas ? Thank you for your help. DG NB : I don't want put the password in the macro, means unprotect and protect the worksheet in the macro... Can you clarify what you mean by Template (i.e. do you have a XLT template, or just a normal XLS workbook)? I'm assuming you have used "Protect Sheet" from the Tools...

XML commands
Hi. I found a very helpfull hint to find formula-cells. The trick is to use the get.cell function. I would like to learn a little bit more about that function. What does 48 or 6 mean in get.cell(48;.... or get.cell(6;... I can't find documentations at the net ? Regards Peter Get.Cell(num, cell reference) is a function from XL4 to return information about the formatting, location or contents of a cell. 48... if cells contain a formula it returns True; if a constant it returns False. 6 ... returns the cell formula Peter Noneley has a free download at... http://homepage.ntlworld.com/no...

Excel VBA
Hi Excel VBA'ers, Via Google I found some great code (see below) that enables MouseDown to paste what's in clipboard. I want this code to apply to ALL of the textboxes in my Userform. Instead of repeating this code multiple times for every textbox, I was wondering how/if I can specify multiple textboxes using the one instance of the code please. (Hmm, if I'm on the right track, perhaps I have to learn about Class Modules to do this??) Here is the code that I found: Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Sing...

Commands are Slow
In the last couple of weeks my commands in Word and Excell have slowed dramatically. I have run disk clean up, defrag, deleted all cookies and temp files,run McAffee and Ad-Aware, but the problem still persists. Any ideas of what I can do to solve this problem ? Thank you Tony ...

Popup Menu command problem
Hi there, I'd like to pop up a context menu when right click the mouse button, but when I click the menu item, applicaiton error appears. Strange thing is this error only happens to Release version. I'm using VC++ 6.0 Here is the code for display the popup menu and it proves to be fine. void CMainFrame::OnContextMenu(CWnd* pWnd, CPoint point) { CMenu menu; menu.LoadMenu(IDR_MENU1) ; CMenu *pmenuPopup = menu.GetSubMenu(0); ASSERT(pmenuPopup != NULL); ClientToScreen ( &point); pmenuPopup->TrackPopupMenu( TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, this...

Blank Userform
Hi all, I have a slight problem, I have some code which adds rows with formfields in to a table in a protected form. These formfields have text in which is dependant upon users ticking checkboxes. Before adding the rows my code checks to see if particular rows have already been added to the table so that these rows are not added again. The whole macro takes about 30 seconds to run and to save users seeing Word 'dance' and the screen flash, I have tried to utilise a userform to appear for the duration of the code. Unfortunately the body of the userform turns bla...

Value error on OR command
I have unput the following formula and instead of getting a false I get a #VALUE! error. Returns true statement if both are true. Does anyone know why this is happening. Seems pretty straightforward. Does not matter if I use find or findb =OR(FINDB("ISO",G2),FINDB("CAN",G2)) Because findb or find return an error if they cannot find the string, wrap both findb formulas with isnumber like =OR(ISNUMBER(FINDB.....),ISNUMBER(FINDB.....)) -- Regards, Peo Sjoblom "#VALUE! Error" <anonymous@discussions.microsoft.com> wrote in message news:032501c3aa...

Is there a command line string I can use to send email?
If I can send email from a command prompt I can figure out a way to do a mass email to a list of people volunteering for something where I work - the list changes daily. Sandra <ab@mdahospital.com> wrote: > If I can send email from a command prompt I can figure out a way to > do a mass email to a list of people volunteering for something where > I work - the list changes daily. Check the tools here: http://www.slipstick.com/addins/mail.htm#massmail -- Brian Tillman ...

Command Buttons
I have 3 command buttons (CB's) linked to macros on a spreadsheet. Two carry out functions, move data, update etc etc. No problem with these. The third is just a button to "Print Page" and when pressed will do just that. The problem is that when pressed the other two CB's move from their position to another part of the spreadsheet. I think the problem is something to do with the selection of the print range, but how do I prevent these buttons from moving i.e. "anchor" them in position. Any help greatly appreciated. Regards John. -- jo2389hn ---------------------...

Background Image on a Userform??? #2
Hi Andy Thanks!!! It worked perfectly... Cheers -- hce ------------------------------------------------------------------------ hce's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3518 View this thread: http://www.excelforum.com/showthread.php?threadid=264974 ...

Vlookup in a userform
Hi, If I enter a number into a userform in a box called 'reference' can I then use a vlookup to fill in the next box 'name' from an external file? I can use the vlookup on a sheet but am not sure of the syntax? within VBa. TIA, Rick With such a generic question a specific answer isn't possible. But in general if you can write a formula in a cell that returns the result you want, yes, you can do it from VB. -- Jim Rech Excel MVP "R D S" <RDS@members.v21.co.uk> wrote in message news:35nl2qF4pjv34U1@individual.net... | Hi, | If I enter a number into a...