Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Is possible?

Discussion in 'Information Technology' started by an, Jul 28, 2006.

Tags:
  1. an

    an
    Expand Collapse
    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
     
  2. Loading...

    Similar Threads Forum Date
    Movies Ashdoc's movie review---Mission impossible 5 Rogue nation Theatre, Movies & Cinema Aug 12, 2015
    India Professor Bhullar's release possible after landmark SC judgement Breaking News Jan 21, 2014
    USA UPDATED! Dr. Prabjot Singh, Sikh Professor Attacked in Possible Hate Crime (2 Videos) Breaking News Sep 23, 2013
    A Shabad I came across - possible interpretations Sikh Sikhi Sikhism Aug 28, 2013
    To know God is to Love him, why this is not possible Sikh Sikhi Sikhism Mar 31, 2012

  3. Dirk Goldgar

    Dirk Goldgar
    Expand Collapse
    Guest

    "an" <an@discussions.microsoft.com> wrote in message
    news:11DDA8F6-46B2-407B-B3CF-D00A1516D6F2@microsoft.com
    > 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.

    --
    Dirk Goldgar, MS Access MVP
    www.datagnostics.com

    (please reply to the newsgroup)
     
  4. Rick Brandt

    Rick Brandt
    Expand Collapse
    Guest

    an wrote:
    > 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"

    --
    Rick Brandt, Microsoft Access MVP
    Email (as appropriate) to...
    RBrandt at Hunter dot com
     
  5. an

    an
    Expand Collapse
    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

    "an" wrote:

    > 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
     
  6. Rick Brandt

    Rick Brandt
    Expand Collapse
    Guest

    an wrote:
    > 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.

    --
    Rick Brandt, Microsoft Access MVP
    Email (as appropriate) to...
    RBrandt at Hunter dot com
     
  7. an

    an
    Expand Collapse
    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

    "Rick Brandt" wrote:

    > an wrote:
    > > 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.
    >
    > --
    > Rick Brandt, Microsoft Access MVP
    > Email (as appropriate) to...
    > RBrandt at Hunter dot com
    >
    >
    >
     
  8. John Vinson

    John Vinson
    Expand Collapse
    Guest

    On Sun, 16 Jul 2006 15:17:01 -0700, an <an@discussions.microsoft.com>
    wrote:

    >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]
     
  9. an

    an
    Expand Collapse
    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


    "John Vinson" wrote:

    > On Sun, 16 Jul 2006 15:17:01 -0700, an <an@discussions.microsoft.com>
    > wrote:
    >
    > >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]
    >
     
  10. Douglas J. Steele

    Douglas J. Steele
    Expand Collapse
    Guest

    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
    http://I.Am/DougSteele
    (no private e-mails, please)


    "an" <an@discussions.microsoft.com> wrote in message
    news:83903361-E334-4C5A-AE94-09C1D6781D34@microsoft.com...
    >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
    >
    >
    > "John Vinson" wrote:
    >
    >> On Sun, 16 Jul 2006 15:17:01 -0700, an <an@discussions.microsoft.com>
    >> wrote:
    >>
    >> >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]
    >>
     
  11. an

    an
    Expand Collapse
    Guest

    JV,

    Problem solved, with:

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

    Thank you.
    an

    "John Vinson" wrote:

    > On Sun, 16 Jul 2006 15:17:01 -0700, an <an@discussions.microsoft.com>
    > wrote:
    >
    > >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]
    >
     
  12. an

    an
    Expand Collapse
    Guest

    RB,

    Problem solved, with:

    On Error Resume Next
    Me!txt... = Me.Cmd1.Name

    Thank you.
    an

    "Rick Brandt" wrote:

    > an wrote:
    > > 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.
    >
    > --
    > Rick Brandt, Microsoft Access MVP
    > Email (as appropriate) to...
    > RBrandt at Hunter dot com
    >
    >
    >
     
  13. Dirk Goldgar

    Dirk Goldgar
    Expand Collapse
    Guest

    "an" <an@discussions.microsoft.com> wrote in message
    news:83903361-E334-4C5A-AE94-09C1D6781D34@microsoft.com
    > 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"



    --
    Dirk Goldgar, MS Access MVP
    www.datagnostics.com

    (please reply to the newsgroup)
     
  14. Pieter Wijnen

    Pieter Wijnen
    Expand Collapse
    Guest

    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" <an@discussions.microsoft.com> wrote in message
    news:83903361-E334-4C5A-AE94-09C1D6781D34@microsoft.com...
    >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
    >
    >
    > "John Vinson" wrote:
    >
    >> On Sun, 16 Jul 2006 15:17:01 -0700, an <an@discussions.microsoft.com>
    >> wrote:
    >>
    >> >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]
    >>
     
  15. Pieter Wijnen

    Pieter Wijnen
    Expand Collapse
    Guest

    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" <an@discussions.microsoft.com> wrote in message
    news:83903361-E334-4C5A-AE94-09C1D6781D34@microsoft.com...
    >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
    >
    >
    > "John Vinson" wrote:
    >
    >> On Sun, 16 Jul 2006 15:17:01 -0700, an <an@discussions.microsoft.com>
    >> wrote:
    >>
    >> >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]
    >>




    --
    ----------------------------------------
    I am using the free version of SPAMfighter for private users.
    It has removed 4231 spam emails to date.
    Paying users do not have this message in their emails.
    Get the free SPAMfighter here: http://www.spamfighter.com/len
     
  16. Michael C

    Michael C
    Expand Collapse
    Guest

    "Rick Brandt" <rickbrandt2@hotmail.com> wrote in message
    news:eFwug.131616$dW3.85462@newssvr21.news.prodigy.com...
    > 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
     
  17. Douglas J. Steele

    Douglas J. Steele
    Expand Collapse
    Guest

    "Michael C" <nospam@nospam.com> wrote in message
    news:eACuwBTqGHA.2232@TK2MSFTNGP04.phx.gbl...
    > "Rick Brandt" <rickbrandt2@hotmail.com> wrote in message
    > news:eFwug.131616$dW3.85462@newssvr21.news.prodigy.com...
    >> 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.


    Huh?

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

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no private e-mails, please)
     
  18. Michael C

    Michael C
    Expand Collapse
    Guest

    "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
    news:e3lBboTqGHA.2232@TK2MSFTNGP04.phx.gbl...
    > 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
     
  19. Larry Linson

    Larry Linson
    Expand Collapse
    Guest

    "Michael C" wrote

    > 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
     
  20. Michael C

    Michael C
    Expand Collapse
    Guest

    "Larry Linson" <bouncer@localhost.not> wrote in message
    news:%23oSEr%23UqGHA.928@TK2MSFTNGP04.phx.gbl...
    > "Michael C" wrote
    >
    > > 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


    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
     
  21. Michael C

    Michael C
    Expand Collapse
    Guest

    "Larry Linson" <bouncer@localhost.not> wrote in message
    news:%23oSEr%23UqGHA.928@TK2MSFTNGP04.phx.gbl...
    > 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
     

Share This Page