![]() |
Date function and combobox
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 |
Date function and combobox
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 "Przemek Wrzesinski" wrote in message ... 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 |
All times are GMT +1. The time now is 01:53 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com