On click and finding the object/component clicked on

I am programming in Access and there are over 60 text boxes all that start with txtTime_##. The program needs to set the value as the current time when clicked. It's fine and dandy to make 60+ txtTime_##_Click() txtTime_##.Value = Now. However, I believe there should be a less time consuming way to do this. There should be a general Click method that captures the clicking of the mouse, correct. Then find out the name of the component that was clicked and if the name has txtTime_ then place now inside of component name. I do not know how to accomplish the general case.

Thank you for any help.

Comments

  • A Control-Array is your friend, but i don't know if Access/VBA supports Control-Array. VB does. Excel doesn't.

    In classic VB you would create a Control-Array containing your 60+ Textboxes. You would have to code the Click-Event only one Time:
    [code]
    Private Sub txtTime_Click(Byval Index as Integer)

    txtTime(Index).Text=Now

    End Sub
    [/code]

    as a sidenote: Textboxes have a "Text"-Property, not "Value"

    : I am programming in Access and there are over 60 text boxes all that
    : start with txtTime_##. The program needs to set the value as the
    : current time when clicked. It's fine and dandy to make 60+
    : txtTime_##_Click() txtTime_##.Value = Now. However, I believe there
    : should be a less time consuming way to do this. There should be a
    : general Click method that captures the clicking of the mouse,
    : correct. Then find out the name of the component that was clicked
    : and if the name has txtTime_ then place now inside of component
    : name. I do not know how to accomplish the general case.
    :
    : Thank you for any help.

    ------------------------------------------
    Only stupidity of mankind and the universe
    are infinite, but i'm not sure concerning
    the universe. A. Einstein
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion