making code more efficient

N

NDBC

After getting a procedure to large error I have finally got around to
reducing my code instead of just having what works.

I have 5 text boxes in a form and at the moment I evaluate each box exactly
the same way but I have sections of code for each box when I could just have
a loop stepping by one.

The boxes are called rider1 through to rider 5. I am having trouble with
this code at the moment

If Rider5.Value < 100 Or IsNumeric(Rider5) = False Then

I have now got

For Box = 5 to 1 step -1

If "Rider" & box.Value < 100 Or IsNumeric("Rider" & box) = False Then

This does not work.

I have also posted this at the bottom of my procedure to large post but
thought more people might see it here.

Any ideas.
 
J

JLGWhiz

The OP said he couldn't get it to work. I am wondering where he has the
code.

If it is behind the user form then:

For box = 1 To 2
MsgBox Me.Controls("rider" & box).Text
Next

If he is trying it from the project module then he will need to make the
form modeless.
 
D

Dave Peterson

Check your other post.
After getting a procedure to large error I have finally got around to
reducing my code instead of just having what works.

I have 5 text boxes in a form and at the moment I evaluate each box exactly
the same way but I have sections of code for each box when I could just have
a loop stepping by one.

The boxes are called rider1 through to rider 5. I am having trouble with
this code at the moment

If Rider5.Value < 100 Or IsNumeric(Rider5) = False Then

I have now got

For Box = 5 to 1 step -1

If "Rider" & box.Value < 100 Or IsNumeric("Rider" & box) = False Then

This does not work.

I have also posted this at the bottom of my procedure to large post but
thought more people might see it here.

Any ideas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top