problem code

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

Forum home » Delegate support and help forum » Microsoft Access VBA Training and help » Problem with code

Problem with code

resolvedResolved · Low Priority · Version 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:

Using the Quick Access Toolbar in Access 2010

The Quick Access Toolbar is included in virtually every Office product, including Outlook 2010, Word 2010, Excel 2010, and PowerPoint 2010.

You will find the Quick Access Toolbar in the top-left side of the window. To begin, click the Customize button (it's the little black arrow at the end of the toolbar).

Simply click the commands you want to include.

Virtually any command can be added to the Quick Access Toolbar. Click the More Commands option and a new window will open from where you can browse the commands including those not on the ribbon.

View all Access hints and tips


Server loaded in 0.08 secs.