function and combobox

G

Guest

Hi all

I am trying to create a function that will take a combo box as an argument
and additem the names of the months to it. the reason for the function is
that i will be using several combo boxes throughout my form with the same data

so far my code is as follows:

<BEGIN VB CODE>
Private Function CreateMonthListBox(MonthListBox&) As ComboBox

CreateMonthListBox.AddItem ("March")
CreateMonthListBox.AddItem ("April")
CreateMonthListBox.AddItem ("May")
CreateMonthListBox.AddItem ("June")
CreateMonthListBox.AddItem ("July")
CreateMonthListBox.AddItem ("August")
CreateMonthListBox.AddItem ("September")
CreateMonthListBox.AddItem ("October")
CreateMonthListBox.AddItem ("November")
CreateMonthListBox.AddItem ("December")
CreateMonthListBox.AddItem ("January")
CreateMonthListBox.AddItem ("February")

Set MonthListBox = CreateMonthListBox
End Function
<END VB CODE>

the line that calls this function is:

CreateMonthListBox (depositMonthList)

depositMonthList is a ComboBox on my form
when i run my code i get the error:

Run-time error'13'
Type mismatch

??? - what am i doing wrong?
 
G

Guest

fixed it -
<BEGIN VB CODE>
Private Sub CreateMonthListBox(MonthListBox as ComboBox)

MonthListBox.AddItem ("March")
MonthListBox.AddItem ("April")
MonthListBox.AddItem ("May")
MonthListBox.AddItem ("June")
MonthListBox.AddItem ("July")
MonthListBox.AddItem ("August")
MonthListBox.AddItem ("September")
MonthListBox.AddItem ("October")
MonthListBox.AddItem ("November")
MonthListBox.AddItem ("December")
MonthListBox.AddItem ("January")
MonthListBox.AddItem ("February")

End Function
<END VB CODE>

and using Call CreateMonthListBox()

works fine now
 
D

Dana DeLouis

If you would like to add month names beginning with the next month, would
any ideas here help?

Dim Mth As Long
Dim MthName As String

For Mth = Month(Now) + 1 To Month(Now) + 12
MthName = MonthName(((Mth - 1) Mod 12) + 1)
CreateMonthListBox.AddItem (MthName)
Next Mth

HTH
 

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

Top