calling sub-routine

  • Thread starter Thread starter Lodewijk
  • Start date Start date
L

Lodewijk

I have a sub-routine that fills in a combobox:

Sub Box(FN, ComboBox, Waarde)
With ComboBox
Do While Not EOF(FN)
Input #FN, MyString
.AddItem MyString
Loop
End With
For teller = 1 To ComboBox.ListCount
If ComboBox.List(teller) = Waarde Then
ComboBox.Text = ComboBox.List(teller)
End If
Next teller
End Sub

I want to use this to fill in all the comboboxes on my form. By calling this
with Call Box(FNBriefLayout, cboBriefLayout, MyUser(10, 3)), where
FNBrieflayout is the FileNumber, and cboBriefLayout is the name of the
combobox, It will not work.
But when I replace cboBriefLayout with "cboBriefLayout" it also does not
works.
How do I call this subroutine so that "With ComboBox" will be the same as
"With cboBriefLayout"?


Lodewijk
 
Lodewijk said:
I have a sub-routine that fills in a combobox:

Sub Box(FN, ComboBox, Waarde)
With ComboBox
Do While Not EOF(FN)
Input #FN, MyString
.AddItem MyString
Loop
End With
For teller = 1 To ComboBox.ListCount
If ComboBox.List(teller) = Waarde Then
ComboBox.Text = ComboBox.List(teller)
End If
Next teller
End Sub

I want to use this to fill in all the comboboxes on my form. By
calling this with Call Box(FNBriefLayout, cboBriefLayout, MyUser(10,
3)), where FNBrieflayout is the FileNumber, and cboBriefLayout is the
name of the combobox, It will not work.
But when I replace cboBriefLayout with "cboBriefLayout" it also does
not works.
How do I call this subroutine so that "With ComboBox" will be the
same as "With cboBriefLayout"?

One problem at least is that an Access combo box -- as opposed the
CommandBarComboBox control -- doesn't have a .List property. Also, a
combo box's list items are number 0 to (ListCount - 1). I think maybe
you should be writing:

'----- start of revised code -----
Sub Box( _
FN As Integer, _
CBox As Access.ComboBox, _
Waarde As String)

With CBox
Do While Not EOF(FN)
Input #FN, MyString
.AddItem MyString
Loop

For teller = 0 To .ListCount - 1
If .ItemData(teller) = Waarde Then
.Value = .ItemData(teller)
Exit For
End If
Next teller
End With

End Sub
'----- end of revised code -----
 
Hi, Lodewijk.

The ComboBox object does not have a List method. I believe you need:

If ComboBox.ItemData(teller) = Waarde Then
ComboBox.Text = ComboBox.ItemData(teller)
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top