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

building forms

ResolvedVersion 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:

Manually wrapping text

To manually wrap text, use the shortcut key Alt+Enter.

To cancel manual text wrapping, simply delete the new line.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.