473,473 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Use a variable to reference a command button

2 New Member
I want to click a command button in code. In place of this: CommandButton1_click, I would like to use a variable like this: Variable_click. What is the syntax for this?
Mar 1 '17 #1
2 3365
jimatqsi
1,271 Recognized Expert Top Contributor
You'll need more than syntax. You'll have to decide on an approach and code the various functions. You might try the Form's On_Click event. In that event you can test the name of the current object (what they clicked on) and then run the code appropriate to that object (Screen.ActiveControl).

Normally that would just be a lot more trouble than using each object's click event. But your situation may demand a more complicated soltution. Tell us more about what you are trying to accomplish. Perhaps there is a better approach.

Jim
Mar 1 '17 #2
zephyr
2 New Member
Looping thru a bunch of cmdbuttons and clicking each if a checkbox next to it is checked. I worked it out a diff way, like this:
'process all boxes
For Each Ctrl In form_mainform.Controls
If TypeName(Ctrl) = "CheckBox" And Ctrl.Name Like "*" & AA & "*" Then
If Ctrl.Value = -1 Then
theState = Mid(Ctrl.Name, 4, 2)
theCmd = "cmd" & theState

Select Case theCmd

Case "cmdaz"
form_mainform.cmdAZ_Click

Case "cmdde"
form_mainform.cmdDE_Click

Case "cmdfl"
form_mainform.cmdFL_Click
....
Instead of calling each button by name separately, I was trying to use something like: Form_MainForm.controls(theCmd)_click in the loop. But what I did works. Still open to suggestions though. Thx.
Mar 1 '17 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mr. Bungle | last post by:
When importing excel from access I am fully aware that one can import directly into a table. Can you get as specific via code or something to import data from an excel sheet to a FORM (Not Table)...
9
by: Melissa | last post by:
What is the code to delete a command button from a form? Can the code be run from the click event of the button to be deleted? Thanks! Melissa
0
by: Lauren Quantrell | last post by:
I use the following code to create text edit fields and command buttons in my toolbars: Function CreateToolbarObject(myObjectType as integer) Dim newObject Select Case myObjectType Case 1...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
3
by: christianlott1 | last post by:
I wouldn't have brought this up except that a friend had a similar problem as well. Situation: Code works fine for months, then suddenly breaks. In my case the code broke on a piece of...
1
by: adrianm4380 | last post by:
Is it possible to call the on click event procedure for a command button on a custom toolbar? I have a menu of buttons that open various forms in varying ways that are all controlled in the on...
5
by: Mike | last post by:
I am calling an event from the on click event of a command button. I cant however figure out how to refrence "which" button was clicked in the first procedure, in the second procedure... In...
5
by: scottbouley | last post by:
I'm trying to create a command button that will perform one action on the first click and another action on the second click. I tried to accomplish it by using a variable but I think the variable is...
1
by: alnino | last post by:
Hi, On a form I have a command button that allows a user to browse for a file (PDF, Word, etc…). This command button then stores a hyperlink to the file within an associated txtfield in the table....
1
by: Tesplund | last post by:
I am using VB to create a code that will save a copy, send it via outlook then delete the copy it saved. I want this to be via command button but am not picky as long as it's as easy as the comman...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.