Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Date function and combobox

IssueDateMonth is a simple variable (Long).

You don't need the Set command.

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

Przemek Wrzesinski wrote:

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


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use match function to add different item in Combobox Leonard Lan Excel Worksheet Functions 2 September 9th 09 06:26 PM
fill combobox depending on selection from another combobox Adam Francis Excel Discussion (Misc queries) 2 July 24th 08 07:39 PM
Format Date ComboBox Blobbies Excel Discussion (Misc queries) 4 January 10th 08 08:40 AM
2 questions! Related to combobox and time function. HELP!! Bruno Excel Discussion (Misc queries) 11 September 28th 07 02:33 PM
Calculating days between current date and a date in future NETWORKDAYS() function Faheem Khan Excel Worksheet Functions 2 February 10th 05 07:18 PM


All times are GMT +1. The time now is 05:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"