2

I have what looks like a very straightforward line of VBA code that is really messing with my head.

id = Form_frm2013_Browser.tb_LineItem_ID.value

When my code reaches this point, I get the following error:

Run-time error '2424': The expression you entered has a field, control, or property name that Microsoft Access can't find

I am pretty sure the problem is the lower-case "v" in value. When I use the intellisense code completion, the property "Value" comes up as upper case, but when I press enter, it goes to lower case. Of course manually attempting to change it doesn't work either--it just goes back to lower case.

By the way, tb_LineItem_ID is the name of a text box control.

Any idea what is going on here?

MrGibbage
  • 2,644
  • 5
  • 39
  • 50
  • Assuming `frm2013_Browser` is currently open in Form View, what do you get in the Immediate window with this? ... `Debug.Print Forms!frm2013_Browser!tb_LineItem_ID.value` – HansUp Jul 11 '13 at 18:35
  • *sigh*... that was it. I was getting some errors in there. Well, that sure a misleading error message. "Can't find" is not the same thing as "bad input". @HansUp, resubmit your comment as an answer and I will mark it as correct. – MrGibbage Jul 11 '13 at 18:38
  • tb_LineItem_ID was a hidden text box on my form. Most of the time it was getting filled in correctly with an integer, but under certain cases, it was getting a #Name? error. When it had that error, that line won't work. I need to fix the #Name? error. You gave me the idea to see what was in the text box. SInce it was hidden, I didn't see it until you suggested it. – MrGibbage Jul 11 '13 at 18:49

2 Answers2

3

Access is complaining it can't find something when you ask for the value of a text box. I can't spot anything wrong in that code line, but sometimes it can be helpful to ask for what you want in a different way.

With frm2013_Browser open in Form View, go to the Immediate window (Ctrl+g), and see what you get with this statement.

Debug.Print Forms!frm2013_Browser!tb_LineItem_ID.value
HansUp
  • 95,961
  • 11
  • 77
  • 135
  • 1
    This directly helped me solve this problem. Most of the time the text box was getting filled in correctly, but under certain circumstances, I was getting a #Name? error, which caused the line of code to fail. I had forgotten about the immediate window. I will now troubleshoot the #Name? error. Thanks, @HansUp – MrGibbage Jul 11 '13 at 18:55
  • You're welcome. I see what you meant about the error message being misleading. The situation wasn't really that Access couldn't find the text box *object*. Rather the text box's value was not accessible due to the `#Name?` error. – HansUp Jul 11 '13 at 18:58
  • Exactly. Still strange about that uppercase-lowercase "Value" though. – MrGibbage Jul 11 '13 at 19:01
  • I've seen that V vs. v plenty of times. I don't know why it happens, but I don't believe it makes any difference. Property names are not case-sensitive. `tb_LineItem_ID.VALUE` should work (or fail) equally well. :-) – HansUp Jul 11 '13 at 19:04
  • 1
    @MrGibbage: See [How does one restore default case to a variable in VBA?](http://stackoverflow.com/q/4852735/154439) for more info on the V vs. v issue. Object properties are treated the same as variables re: case changes within the VBA IDE. In other words, to "fix the casing" of the `.value` you need to add a line somewhere that says `Dim Value`. You may then delete that line. The properly cased `.Value` will remain. It sounds confusing; you almost have to see it to believe it. – mwolfe02 Jul 14 '14 at 20:05
0

For me, The control had to be enabled first.

n.b. and do not disable it within the same sub/fun.

Smart.Man
  • 41
  • 5