Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2004
    Posts
    364

    Unanswered: Display the value of a field in a label instead of a textbox?

    Is there a method to display the value of a field from a query or a table in a label instead of a textbox?

    I have some labels which are set to visible=no, with a short message of text which will only display (visible=true) if a certain value is met and I would like to display the value alongside the text if the value is met instead of in a seperate textbox.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you can set the value of a label as required
    however it will only work with non continuous forms

    place some code in the forms "on current" event
    mylable.caption = "blah di blah:" & myrecordset.columnname

    I get confused with the various differences betwen VBA, VB & different versions so it may be
    mylable.text.
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Aug 2004
    Posts
    364
    Thankyou for replying, Im struggling a bit with my code for the on-current event. The query is called Query5, and the column is called ItemID and is the first column.

    What should my correct code be, this is what I have come up with but obviously is doesnt work because it is incorrect..

    Code:
     Dim db            As DAO.Database
      Dim rs            As DAO.Recordset
      Set db = CurrentDb()
      Set rs = db.OpenRecordset("query5)", dbOpenDynaset, dbAppendOnly)
      Label24.Caption = "blah di blah:" & rs.query5.column(0)

  4. #4
    Join Date
    Aug 2004
    Posts
    364
    I think I got it -
    Code:
    Dim db As DAO.Database
      Dim rs As DAO.Recordset
    
      Set db = CurrentDb()
      Set rs = db.OpenRecordset("Query5", dbOpenDynaset, dbAppendOnly)
    
    Label24.Caption = "blah di blah:" & rs!itemID

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if the column you want is already part of the underlying query used in the form you should be able to use that column directly
    in which case you dont' need to defien a recordset or query

    IIRC its going to be something like me.recordsource.mycolumnname

    best thing to do is to put a watch/breakpoint in the on current event
    then examine the properties of the various objects int he immediate window
    try ?mycolumnanme
    the ? tells the immediate window to show the resutls of the following
    so ?mycolumnanme mean show me the value of mycolumname

    ?label1.caption mesans show the value of the caption property in label1

    you can set vlazues aswell

    eg
    label1.caption = "oojamacallit"
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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