Date function and combobox

  • Thread starter Thread starter Przemek Wrzesinski
  • Start date Start date
P

Przemek Wrzesinski

Hi,

I've got a problem with implementing Date function into combobox. I've got 3
comboboxes in my user form, one combo for day, second one for month and last
one for year. I know that I can add item to combobox via .AddItem method but
after this I want set the values (listindex) of these combo's to system
date, instead of clicking by user, something like this:

Dim IssueDate As Date
Dim IssueDateYear As Long
Dim IssueDateMonth As Long
Dim IssueDateDay As Long
Set IssueDate = Date
Set IssueDateMonth = Month(IssueDate)

With myform.IssueDateMonthCombobox
.Clear
.AddItem (IssueDateMonth-1) ' last month
.AddItem (IssueDateMonth)
.AddItem (IssueDateMonth+1) 'next month
.ListIndex = ' set to IssueDateMonth
End With

When I'm trying to run this, Excel is saying "object required' and marking
line "Set IssueDateMonth = " and "Private Sub UserForm_Initialize()" :-/

Has anyone dealt with this ?

TIA

Przemek
 
Przemek,

Are you sure that 'IssueDateMonthCombobox' is the name of your combobox.
Look at the Name property of the box in design mode.

Naming a variable (IssueDateMonth) the same or similar to your controls
can get very confusing. Try renaming your variable to something like IDM.
You know what it means and a comment on the Dim line can explain it to
others.
You'll save on the typing as well.

HTH
Henry
 
IssueDateMonth is a simple variable (Long).

You don't need the Set command.

You do need Set with objects (like ranges, worksheets, workbooks).
 
Back
Top