Results 1 to 8 of 8
  1. #1
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Updating text box or label from table (XP, 2000)

    I have a form based on "Table A" with a textbox control. I removed the label of the textbox control and replaced with another textbox control formatted to look like a label. I would like for the content of that textbox to be taken from a field in "TableB". Is this possible? What I am trying to do is make the "field name" of the first textbox I mentioned customizable. In other words, you can "relabel" that field by simply changing a value in TableB.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Updating text box or label from table (XP, 2000)

    Not enough info to give specific advice. Depends on how the value is to be retrieved. Perhaps a Control Source like

    =DLookup("FieldName", "TableB")

    or

    =DLookup("FieldName", "TableB", "SomeCondition")

  3. #3
    Star Lounger
    Join Date
    Jan 2003
    Location
    Grass Valley, California, USA
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating text box or label from table (XP, 200

    Don,

    Rather than removing the label, you can overwrite the label caption from within any VBA code with the "field name" of your choice. You can't make the overlay automatic, but you can manually code an assignment statement like the following:

    me.lblTxtBox.caption = strNewLabel

    or

    me.lblTxtBox.caption = rst!TableBField

    if you have rst opened to the "TableB" that contains the label value you want.

    I have used this technique for modifying labels for textboxes, combo boxes, and even command buttons. Works like a charm!

    -- Jim

  4. #4
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating text box or label from table (XP, 200

    Thanks to both Hans and Jim. I guess that is the question - how do I want to retrieve the data. I thought I could simply identify that table and field as the control source but that doesn't work. I tried the =dlookup("fieldname","tablename") and that resulted in #Error.

    Jim, I don't know what rst is but i guess, i could rename the label as a current event of the form... but how would I retrieve the field value from tableB in order to rename the label caption?

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Updating text box or label from table (XP, 200

    You will have to provide some information about how you want to set up things. Is TableB going to contain one record, or several, and is it going to contain one field, or several? You can't expect us to conjure up advice out of nothing.

  6. #6
    Star Lounger
    Join Date
    Jan 2003
    Location
    Grass Valley, California, USA
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating text box or label from table (XP, 200

    Don,

    The "rst" is nothing more than an open ADO table Recordset pointer; in this case for "TableB". I'm not sure what you mean by "...rename the label as a current event of the form...". While labels can have associated events, I don't see any usage here. Rather, some other event that is causing your need to relabel the underlying textbox control is the event that should cause you to determine the alternative label and assign it to the textbox label caption.
    I'll admit that I've never had to pickup a dynamically defined label caption from another table. Usually, when I change label captions, it is from a small set of predefined captions that I can determine from within VBA logic, and then assign to the caption from a constant character string within the VBA code. If you truly need to have it dynamic from another table, then I think you'd need to have some type of associated lookup key on the label, and issue an ADO find method to get the caption value for assignment.

    -- Jim

  7. #7
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating text box or label from table (XP, 200

    Okay, I wondered what else I could provide. Now I know. TableB will contain a single record with several fields. I have already used one field successfully to fill a textbox on another form but that form is only associated with tableB. Now, on a different form, I want to refer again to tableB only to a different field.

    BTW, who says you can't conjure up advice out of nothing? You guys are magic and I have seen it many times. (smile). Thanks for all the help.

  8. #8
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating text box or label from table (XP, 200

    I got it to work. I was using the =dlookup incorrectly. I forgot the [ ] around the field name. Thanks to all.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •