Handling months and years
Reader Bayer White offers an efficiency boost in dealing with the date we all deal with year in and year out.
From most of the code I've seen from other developers, I think they lean toward hard coding Month Names and 4 digit years into combo boxes. This can take unneeded lines of code, and it is not very manageable if requirements change in the future. That's why I decided to write a more effecient, manageable way of dealing with dates. Hope this helps!!!
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
**********Loading Full Month or Full Year into a combo box*********** Option Explicit Private Enum DateType FullMonth = 1 FourDigitYear = 2 End Enum Private Sub LoadDateComboBoxes(cboBox As ComboBox, _ DateFormat As DateType) Dim intMonthCtr As Integer Select Case DateFormat Case 1 'Just full month For intMonthCtr = 1 To 12 cboBox.AddItem Format(DateAdd("m", intMonthCtr, "12/1"), "mmmm") cboBox.ItemData(cboBox.NewIndex) = Month(DateAdd("m", intMonthCtr, "12/1")) Next Case 2 'Just 4 digit year For intMonthCtr = -2 To 10 cboBox.AddItem Year(DateAdd("yyyy", intMonthCtr, Now)) Next End Select End Sub
Thanks, Bayer. For your interest in SearchVB, we'll be sending you a free denim shirt.
Bayer White is a Senior VB Developer for Baywood Technologies, in Jacksonville Florida.