building forms

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Building Forms

Building Forms

resolvedResolved · Medium Priority · Version 2003

Babawande has attended:
Excel VBA Intro Intermediate course
Excel VBA Advanced course

Building Forms

I attended VBA Introduction-Intermediate training programme last week; I have a question concerning the exercise we did in class.

Below is an extract from the exercise, this relates to building “forms”.

-------------------------------------------------------------------------------------------------------
Private Sub cmbRepType_AfterUpdate()

Dim IntRowCount As Integer
Dim intIndex As Integer

intIndex = 0

Call DeleteEntries

If Me.cmbRepType.Value = "Sales Person Report" Then

For IntRowCount = 2 To Sheets("List Page").Range("a1").CurrentRegion. _
Rows.Count

Me.cmbSelection.AddItem Sheets("List Page").Cells(IntRowCount, 1).Value, _
intIndex

intIndex = intIndex + 1

Next IntRowCount


Else

For IntRowCount = 2 To Sheets("List Page").Range("c1").CurrentRegion. _
Rows.Count

Me.cmbSelection.AddItem Sheets("List Page").Cells(IntRowCount, 3).Value, _
intIndex

intIndex = intIndex + 1

Next IntRowCount

End If

End Sub

-------------------------------------------------------------------------------------------------------
Sub DeleteEntries()

Dim IntRowCount As Integer

For IntRowCount = Me.cmbSelection.ListCount - 1 To 0 Step -1

Me.cmbSelection.RemoveItem IntRowCount

Next IntRowCount

End Sub

--------------------------------------------------------------------------------------------

I noticed that running the code, with or without “DeleteEntries”, (that is, not calling “DeleteEntries” from procedure: “cmbRepType_AfterUpdate”) does not make a difference to the final result.

In future, if I want to build a similar model, must I include “DeleteEntries” code?

Kind regards


Wande

RE: Building Forms

Hi Wande

Thanks for your question

The fact that the deleteentries procedure seems to make no difference is down to the fact that we are explicitly specifying the index number of each entry; thus it overwrites the corresponding entry.
However, it cannot be guaranteed that the index numbers will always be equal, and thus it is good practice to include the DeleteEntries procedure

Regards

Stephen

Tue 3 Aug 2010: Automatically marked as resolved.

 

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.


 

Excel tip:

Excel 2010 Shortcuts - Start and End of the Worksheet

Did you know you can quickly move to either the beginning or the end of an Excel Worksheet using just a couple of keys on the keyboard?

Press Ctrl + Home key to move the cursor to cell A1

Press Ctrl + End key to move the cursor to the end of the current worksheet.

View all Excel hints and tips


Server loaded in 0.07 secs.