Results 1 to 5 of 5
  1. #1
    MattLewis is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Posts
    17

    Am I stupid, or.....

    I'm having trouble getting the value of a TextBox in VBA code. Either I'm stupid or Access is utterly ridiculous.



    Ultimately, I'm trying to open a form using a where clause which is built based on the current value of a TextBox. The TextBox which has the string I want has a ControlSource set and it changes automatically based on which record is currently selected on the containing form.

    Code:
    DoCmd.OpenForm FormName:="JobDetails", WhereCondition:="JobRef = '" & JobID.Value & "'"
    I've narrowed the problem down to the fact that the current value of the text box is (apparently) not accessible at run-time. Here is an example (name of TextBox is JobID):

    Code:
    MsgBox Me.JobID.Value
    The string returned by JobID.Value is a string of 8 question marks "????????". I also tried:

    Code:
    MsgBox Me.JobID.Text
    That was an error because JobID didn't currently have focus. This is cheesy because why does it EFFING matter what has focus? Then I tried:

    Code:
    MsgBox Me.JobID
    That also returns 8 question marks.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    You don't need the .value, me.jobID will give the value.
    ???? Could be a format issue.
    the text box doesn't need the focus,BUT the form with it does.

  3. #3
    MattLewis is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Posts
    17
    .Value or Me.JobID, they are both returning something that renders as "????????". They should be returning a string and that string should be the value of what is currently in that TextBox, and it's not. Hence the problem. For example, if JobID was currently "123456", then the string returned by Me.JobID should be "123456"

    To be clear, the TextBox is plain text with basic alphanumeric characters (no extended or UNICODE or anything weird like that). There should be no "format issue"

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    FYI, focus is required when referring to the Text property. What event is the code in? Can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    MattLewis is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Posts
    17
    OK, After going through a bunch different tests, I've isolated the problem: The TextBox in question is bound to an AutoNumber with format of ReplicationID. If I re-create everything but with a long integer format (all other things the same), it works.

    So, moral of the story: Access VBA doesn't return the expected string for TextBoxes bound to an AutoNumber of format ReplicationID

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

Similar Threads

  1. Feeling really stupid
    By Gina Maylone in forum Access
    Replies: 8
    Last Post: 05-24-2015, 12:24 AM
  2. Being Stupid - #div/0
    By Epona in forum Queries
    Replies: 1
    Last Post: 06-09-2012, 09:15 AM
  3. Maybe a stupid question
    By rbiggs in forum Programming
    Replies: 1
    Last Post: 08-23-2011, 05:29 PM
  4. I can't be this stupid
    By corquando in forum Import/Export Data
    Replies: 2
    Last Post: 03-01-2010, 04:12 PM
  5. Why is Access so stupid?
    By dvongrad in forum Queries
    Replies: 1
    Last Post: 11-14-2009, 10:14 AM

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