Results 1 to 3 of 3
  1. #1
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159

    Adding textbox.text to a string variable...

    Thanks to anyone willing to help. Here is a simple block oferroneous code:

    Private Sub Command19_Click()
    Dim myString as String
    myString = TextBoxName.Text


    This produces an error "You can't reference a property or method for a control unless the control has the focus". Is there another way to gather the Text from that textbox programmatically?



    Thanks
    MG

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You are wanting the .Value property

    Me.TextBoxName.Value

  3. #3
    ipisors is offline Access Developer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    119
    And I would just like to clarify. You can use .Text if that control does have the focus. Why would that ever be useful? If the .Value property hasn't been updated yet...Like it won't if you haven't exited the control yet.

    Also worth bringing up: You can use .Value if just referencing the value of a control. However, it's also good to disambiguate your Control names from their ControlSource names. For example, if your Controlsource field is called dtCreated, then call your textbox txtdtCreated (or something) - that way it's clear what you're coding. Because the underlying ControlSource table field won't have been updated yet, but the Control will.

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

Similar Threads

  1. Preserving String variable formatting in text box
    By Monterey_Manzer in forum Forms
    Replies: 5
    Last Post: 06-18-2013, 09:39 AM
  2. Replies: 3
    Last Post: 05-28-2013, 12:53 PM
  3. Extract Value from Variable in String
    By nguyenak in forum Programming
    Replies: 3
    Last Post: 05-24-2012, 03:50 PM
  4. Replies: 7
    Last Post: 02-21-2012, 05:48 PM
  5. Adding Hyperlink into Textbox with Text
    By tylerg11 in forum Forms
    Replies: 5
    Last Post: 11-07-2011, 01:58 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