Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

problem code

ResolvedVersion 2003

Joanne has attended:
Access VBA course

Problem with code

Hi I seem to keep getting and error with the code. It works fine if I copy and paste the code but when I type it in it stops at Me.lstNumbers.AddItem intCount. Can you see where I am going wrong please.

Option Explicit

Private Sub cmdNumbers_Click()
Dim intStart As Integer
Dim intFinish As Integer
Dim intCount As Integer

intStart = InputBox("Enter a number")
intFinish = InputBox("Enter a higher number")
intStart = intCount

Me.lstNumbers.RowSourceType = "Value"

Do While intCount <= intFinish

Me.lstNumbers.AddItem intCount
intCount = intCount + 1

Loop

Do Until intCount > intFinish

Me.lstNumbers.AddItem intCount
intCount = intCount + 1

Loop


End Sub

RE: Problem with code

Hi Joanne,

Thank you for your question.

The only mistake I can see is the rowsourcetype is a value list not a value.

I hope this resolves the problem. If not let me know.

Regards

Simon

RE: Problem with code

Hi Simon I put the "Value List" in and the code now runs but it does not start with the first number that I enter. If I type in 5 and the finish 8, it starts at 0? 012345678. Can you see where the code is wrong?
Thanks Jo

RE: Problem with code

Hi Jo,

Thanks for the clarification.

This line of code needs to be changed:

intStart = intCount

This should be intCount = intStart as the intCount needs to hold the value of your starting input box which is intStart. That is why it keeps doing 0 to your finish number.

I hope this helps.

Regards

Simon

RE: Problem with code

Thanks Simon, I couldn't see for looking!! Makes sense now, once again thanks for your help
Jo

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Access tip:

Add current time to a field

Press CTRL+SHIFT+ SEMICOLON

View all Access hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.