General
Dim rsBrand As New ADODB.Recordset
Private Sub Form_Load()
rsBrand.Open "tblBrand", Cnn, , adLockOptimistic
End Sub
Private Sub cboBrand_DropDown()
Call PopulateCombo(cboBrand, rsBrand, 1)
End Sub
Public Sub PopulateCombo(ByVal cbo As ComboBox, ByVal rs As ADODB.Recordset, ByVal No As Integer)
With rs
.Requery
Do While Not .EOF
cbo.AddItem IIf(cbo.Name = "cboBrand", .Fields(No), .Fields(1) & " " & .Fields(2))
.MoveNext
Loop
End With
There is the error message "Run-time error '3265': Item cannot be found in the collection corresponding to the requested name or ordinal." and the line cbo.AddItem IIf(cbo.Name = "cboBrand", .Fields(No), .Fields(1) & " " & .Fields(2)) is highlighted.
Placing the cursor on .Fields(2) shows the error message. The error is because tblBrand has only 2 fields. However, since cbo.Name = "cboBrand", does VB6 not go only to the True part (.Fields(No))? It looks at the False part (.Fields(1) & " " & .Fields(2)) also (and thus causes the error)?
I prefer the Inline IF function to the If...Then...Else statement for IIF takes only 1 line. I will have to use If...Then...Else if IIF does not work in this case. What about the advantages and disadvantages of each over each other?
This post has been edited by AN1554: 22 April 2012 - 03:26 AM

New Topic/Question
Reply



MultiQuote





|