Is possible?

G

Guest

Hi!

Is possible in a textbox show us the name of the command button, after
clicked it?.

For another words:
I would like, after click on command button, transfer the name or control of
this button to a textbox, in same form.

Is it possible, please?

Thanks in advance.
an
 
D

Dirk Goldgar

an said:
Hi!

Is possible in a textbox show us the name of the command button, after
clicked it?.

For another words:
I would like, after click on command button, transfer the name or
control of this button to a textbox, in same form.

Is it possible, please?

Thanks in advance.
an

I'm not sure what you're after. You could certainly hard-code the name
assignment in the button's Click event procedure:

Private Sub cmdMyButton_Click()

Me!txtMyTextbox = "cmdMyButton"

End Sub

Or you could have a more general-purpose function in the form's module,
that uses the form's ActiveControl property to get the name of the
current control, which should be the button:

Function SendControlName()

On Error Resume Next
Me!txtMyTextbox = Me.ActiveControl.Name

End Function

But you'd still have to call the function from the button's Click event.
 
R

Rick Brandt

an said:
Hi!

Is possible in a textbox show us the name of the command button, after
clicked it?.

For another words:
I would like, after click on command button, transfer the name or
control of this button to a textbox, in same form.

Is it possible, please?

Thanks in advance.
an

Only if the code being run by the command button puts it there.

Me!TextBoxName = "ButtonName"
 
G

Guest

Sorry to both.

In adition:
I have two command buttons.
Cmd1 and Cmd2
I would like "transpose" to textbox the Cmd1 or Cmd2 name, as click in one
or another button.

an
 
R

Rick Brandt

an said:
Sorry to both.

In adition:
I have two command buttons.
Cmd1 and Cmd2
I would like "transpose" to textbox the Cmd1 or Cmd2 name, as click
in one or another button.

Then you will need to modify the code of both buttons to make that happen.
 
G

Guest

RB, thank you for your reply.

I tried your solution but with quotations marks:
“sintax errorâ€

without quotations marks, don´t transpose the command button control (?)

an
 
J

John Vinson

RB, thank you for your reply.

I tried your solution but with quotations marks:
“sintax error”

without quotations marks, don´t transpose the command button control (?)

Please copy and paste your actual code.

There is an error in the code. None of us can see what that error is,
because we cannot see your computer.


John W. Vinson[MVP]
 
G

Guest

J V, thanks too.

I put next code in Event Procedure in On click of the command button cmdNa

On Error Resume Next
Me!txtNameChoosed = Me.ActiveControl.cmdNa

Where:
- txtNameChoosed, is the name of the textbox to receive the name of the
command button;
- cmdNa, is the name of the command button
 
D

Douglas J. Steele

If cmdNa is the active control, you should have

Me!txtNameChoosed = Me.ActiveControl.Name

If it's not, just put

Me!txtNameChoosed = "cmdNa"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)
 
G

Guest

JV,

Problem solved, with:

On Error Resume Next
Me!txtNameChoosed = Me.cmdNa.Name

Thank you.
an
 
D

Dirk Goldgar

an said:
J V, thanks too.

I put next code in Event Procedure in On click of the command button
cmdNa

On Error Resume Next
Me!txtNameChoosed = Me.ActiveControl.cmdNa

Where:
- txtNameChoosed, is the name of the textbox to receive the name of
the command button;
- cmdNa, is the name of the command button

I think you misunderstood my post. When I said to use

Me.ActiveControl.Name

I meant exactly that; literally. You see, the form's ActiveControl
property returns a reference to the control on the form that has the
focus. So it gives you back a Control object, and from that object you
want to get the value of the Name property.

If you wanted to hard-code the name of the control, there'd be no need
to use ActiveControl.Name. You would just write

Me!txtNameChoosed = "cmdNa"
 
P

Pieter Wijnen

Me!txtNameChoosed = Me.ActiveControl.Name

"Me" is The Current Form
"ActiveControl" is the commandbutton
"Name" is the Name of the commandbutton

Me!txtNameChoosed="cmdNa"
would give the same result

FYI
the full syntax would be:
Me.Controls("txtNameChoosed").Value =
Me.ActiveControl.Properties("Name").Value
or
Me.Controls("txtNameChoosed").Value =
Me.Controls("cmdNA").Properties("Name").Value

Hope this clarifies

Pieter
 
P

Pieter Wijnen

Me!txtNameChoosed = Me.ActiveControl.Name

"Me" is The Current Form
"ActiveControl" is the commandbutton
"Name" is the Name of the commandbutton

Me!txtNameChoosed="cmdNa"
would give the same result

FYI
the full syntax would be:
Me.Controls("txtNameChoosed").Value =
Me.ActiveControl.Properties("Name").Value
or
Me.Controls("txtNameChoosed").Value =
Me.Controls("cmdNA").Properties("Name").Value

Hope this clarifies

Pieter


an said:
J V, thanks too.

I put next code in Event Procedure in On click of the command button cmdNa

On Error Resume Next
Me!txtNameChoosed = Me.ActiveControl.cmdNa

Where:
- txtNameChoosed, is the name of the textbox to receive the name of the
command button;
- cmdNa, is the name of the command button



--
 
M

Michael C

Rick Brandt said:
Only if the code being run by the command button puts it there.

Me!TextBoxName = "ButtonName"

This is a pretty inefficient way to get a reference to a textbox. You're
forcing access to search through the controls collection by name to find the
textbox instead of just using the reference to the textbox directly.

Michael
 
D

Douglas J. Steele

Michael C said:
This is a pretty inefficient way to get a reference to a textbox. You're
forcing access to search through the controls collection by name to find
the textbox instead of just using the reference to the textbox directly.

Huh?

Me!TextBoxName references the textbox directly and puts the literal string
"ButtonName" in it.
 
M

Michael C

Douglas J. Steele said:
Huh?

Me!TextBoxName references the textbox directly and puts the literal string
"ButtonName" in it.

No it doesn't. It's equivelant to Me.Controls("TextBoxName").Value =
"ButtonName"

This causes access to search through the control array for the textbox based
on it's name. Me.TextBoxName will give a compile time error if TextBoxName
doesn't exist where Me!TextBoxName will give a runtime error. It's always
better for the compiler to pick up the errors. You also get the disadvantage
that any calls to functions on the textbox will be latebound using ! and
will not be picked up until runtime if they are incorrect also.

Michael
 
L

Larry Linson

No it doesn't. It's equivelant to
Me.Controls("TextBoxName").Value =
"ButtonName"

Help me understand, if you're not _just_ raising objections: what approach
do you suggest that is more "efficient"? I've used the normal method of
addressing controls (to which you object) since Access 1.1, and never
suffered any discernable performance hit from it.

And, if you have something that is more efficient, in how large a loop would
it have to be tested to show a measurable performance improvement?

Larry Linson
Microsoft Access MVP
 
M

Michael C

Larry Linson said:
Help me understand, if you're not _just_ raising objections: what approach
do you suggest that is more "efficient"? I've used the normal method

I would not call ! the "normal" method. The normal method would be to use .
like everywhere else in the language.
of addressing controls (to which you object) since Access 1.1, and never
suffered any discernable performance hit from it.

Most likely in access you won't notice any performance hit. However, compare
the methods:

Using Me.MyControlName.Value
- this gets a direct reference to the control
- calls Value early bound so is as quick as you can get in access.

Using Me!MyControlName.Value
- this will get a reference to the controls collection
- enumerate through the controls collection comparing on the string
"MyControlName"
- then return an object
- then iterate through all the methods on the control looking for one called
Value, again a string comparison.
- then convert all parameters to variant (in this case only 1 param) and
call invoke (a hidden method).
- or alternatively search for the default method if the .Value is not used.

All of this is pretty inefficent. Sure it might not make that much
difference unless it's in a loop but there is no gain using ! so why not
just use a dot?
And, if you have something that is more efficient, in how large a loop
would it have to be tested to show a measurable performance improvement?

The loop wouldn't have to be that big really but probably several thousand.
However speed is not really the main issue here. Using the ! means errors in
your code will be detected at runtime and not compile time and it is always
better to have the compiler pick up errors instead of the programmer, or
even worse the user.

Michael
 
M

Michael C

Larry Linson said:
Help me understand, if you're not _just_ raising objections: what approach
do you suggest that is more "efficient"? I've used the normal method of
addressing controls (to which you object) since Access 1.1, and never
suffered any discernable performance hit from it.

And, if you have something that is more efficient, in how large a loop
would it have to be tested to show a measurable performance improvement?

I should also add that using Me.MyControlName also has the advantage that
intellisense works when you push dot after MyControlName or even after Me.

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top