Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Building Forms
Building Forms
Resolved · Medium Priority · Version 2003
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
For upcoming training course dates see: Pricing & availability
RE: Building Forms
Hi WandeThanks 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.
|



Course updates

