1

So I'm attempting to change the value of a textbox on a form with VBA code.

I'm actually doing this by running a string as code so I can loop through a number of textboxes that are named similarly (RacewayOrder1, RacewayOrder2, etc...) and populate them all one at a time. So my code looks like this:

Private Sub FillRow(ByVal OrderNumber As Integer)

Dim tempstr As String
tempstr = "RacewayOrder" & OrderNumber & " = " & OrderNumber
Eval (tempstr)

End Sub

However, I am getting runtime error 2482 "Database cannot find the name 'RacewayOrder1' you entered in the expression"

I have verified that this isn't a typo, as I copied the text box's name directly into vba, but that doesn't seem to help. I even created the tempstr variable so I could inspect the code it is attempting to run, but that hasn't helped at all either.

To make matters more annoying, I debug.printed tempstr and pasted it in as a command, and it works fine.

enter image description here

Any advice?

0

1 Answer 1

2

You can't use Eval() to assign a value to your text box. If you overcome the RacewayOrder1 not found problem, Eval() will treat your string expression as a test for equality, not as a value assignment.

Forget about Eval() for this and simply reference the text box by name in the form's Controls collection:

Me.Controls("RacewayOrder" & OrderNumber).Value = OrderNumber
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.