Results 1 to 4 of 4
  1. #1
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53

    Need some help explaining something with VBA controls

    What is the difference between CONTROL.value and CONTROL.text ?



    I still can't understand the difference.

    I have done searches, and read through what Microsoft has to say and I still don't get it.

    Thanks.

    Ken L

  2. #2
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Use .text to get what's being written in "real time", usually within a change event. Just make sure your control has focus. Test both value and .text within a change event to know what I'm saying.
    Code:
    Private Sub YourControl_Change()
        Debug.Print YourControl.Text, YourControl.Value
    End Sub
    You'll notice that .value is:
    If new record = null
    If existing record = the value when you opened the form or the value when you navigated to that record

    But .Text is the current content of the control.

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Put another way
    .Text is the unsaved version of what a textbox contains.
    .Value is what was last saved in the record. It may or may not be the same as what the underlying field contains.
    It's not the same when you have unsaved edits...
    ?forms![attendance log1].DateV.value
    1/02/27 4:00:00 AM

    ?forms![attendance log1].DateV.text
    1/02/2027 4:00:00 PM

    IIRC, that means the control has to be bound, otherwise there would be no distinction between the two. M$ documentation does not make that distinction but it makes sense to me. Lastly, a control has to have the focus in order to get/set its .Text property.

    And for those wondering, the object names from this db are not of my creation.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I would also throw in

    .value is the default property of a control and does not need to be specified

    there is another property .oldvalue

    this is only populated with bound controls and contains the value when the form is first loaded

    so the sequence might be

    form is loaded- oldvalue and value contain the value of the underlying field
    user clicks on the control (it has the focus) - the text property is assigned the value which user can edit.
    User leaves the control (loses focus)- value is assigned the text value and the text property is no longer available

    Note that for certain field types such as dates are stored as numbers - that is what will be in the oldvalue and value properties, text shows the text format of that numeric value so you can edit it

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 14
    Last Post: 03-23-2023, 05:45 AM
  2. Using Tab Controls
    By NadiaWilkes in forum Programming
    Replies: 7
    Last Post: 02-14-2020, 06:07 PM
  3. Replies: 3
    Last Post: 04-29-2017, 12:09 PM
  4. Replies: 10
    Last Post: 11-16-2016, 07:59 AM
  5. Replies: 6
    Last Post: 08-04-2010, 01:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums