Getting a caption without naming the control

Discussion in 'Access Forms Coding' started by Rod Speed, Aug 2, 2012.

  1. Rod Speed

    Rod Speed Guest

    I have a form with a considerable number of buttons
    which each set a timer with a variable amount of time.

    Obviously each button is labelled with the time to be set.

    I want to have general purpose code on the click event
    which uses the value that is specified in the caption.

    But I don't want to have to name the control, I want
    to just use a generic reference to the caption so the
    same code can be used when each button is clicked.

    How do I reference the caption in the .Caption form ?
     
    Rod Speed, Aug 2, 2012
    #1
    1. Advertisements

  2. Rod Speed

    Jon Lewis Guest

    Like this:

    Function DoSomething(What As String)
    MsgBox What
    End Function

    Each button's click event:

    '=DoSomething([Screen].[ActiveControl].[Caption])'
    (without the quotes)

    HTH



    "Rod Speed" <> wrote in message
    news:...
    >I have a form with a considerable number of buttons which each set a timer
    >with a variable amount of time.
    > Obviously each button is labelled with the time to be set.
    > I want to have general purpose code on the click event
    > which uses the value that is specified in the caption.
    > But I don't want to have to name the control, I want
    > to just use a generic reference to the caption so the
    > same code can be used when each button is clicked.
    > How do I reference the caption in the .Caption form ?
     
    Jon Lewis, Aug 3, 2012
    #2
    1. Advertisements

  3. Rod Speed

    Rod Speed Guest

    Jon Lewis <> wrote

    > Like this:


    > Function DoSomething(What As String)
    > MsgBox What
    > End Function


    > Each button's click event:


    > '=DoSomething([Screen].[ActiveControl].[Caption])'
    > (without the quotes)


    > HTH


    Thanks for that, exactly what I wanted.

    >
    >
    > "Rod Speed" <> wrote in message
    > news:...
    >>I have a form with a considerable number of buttons which each set a timer
    >>with a variable amount of time.
    >> Obviously each button is labelled with the time to be set.
    >> I want to have general purpose code on the click event
    >> which uses the value that is specified in the caption.
    >> But I don't want to have to name the control, I want
    >> to just use a generic reference to the caption so the
    >> same code can be used when each button is clicked.
    >> How do I reference the caption in the .Caption form ?

    >
    >
     
    Rod Speed, Aug 4, 2012
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.