Popup menu

How can i control the end user using 3 popup menu to choose a date of birth. 1 for date, 2 for month, 3 for year. i want to prevent end user to choose the existing date. For example, I don’t want the user to choose 31/February/2001,For such date never exist. Thanks

The selection order:

Enable the year by default, and once the user choose one, select the month.
Once the user set a month, enable the day.

Check what the user choose (28, 29, 30 or 31 days) and act accordingly depending of 365/366 days / the month #.

Is it clear ?

Oh great @ Emile Schwarz. thanks for that. i will try that.

Here is what you need to do:

Create two popup menus

popupmenu1 - Open Event

[code] Dim rows(11) as string
rows(0) = “January”
rows(1) = “February”
rows(2) = “March”
rows(3) = “April”
rows(4) = “May”
rows(5) = “June”
rows(6) = “July”
rows(7) = “August”
rows(8) = “September”
rows(9) = “October”
rows(10) = “November”
rows(11) = “December”

me.addrows rows[/code]

Popupmenu1 - Change Event

[code] popupmenu2.DeleteAllRows
dim numberofdays as integer = 30

if me.text = “january” or me.text = “March” or me.text = “May” or me.text = “July” or me.text = “August” or me.text = “October” or me.text = “December” then
numberofdays = 31
elseif me.text = “February” then
numberofdays = 28
else
numberofdays = 30
end

dim n as integer
for n=1 to numberofdays
popupmenu2.addrow str(n)
next[/code]

Popupmenu2 - Open Event

me.addrow "---"

That works fine in case of a single language. In order to be language independent, you can use the listindex property. Something like this: (syntax may need adjustment)

select case me.listindex // 0 based
case 0,2,4,6,7,9,11
NumberOfDays = 31
case 1
NumberOfDays = 28
Case 3,5,8,10
NumberOfDays = 30
case else
return
end select

This doesn’t handle Leap years very well though. I prefer to use the date class to get the number of days in a month.

Assuming you have three popupmenus named YearMenu, MonthMenu & DayMenu. YearMenu will have a range of acceptable years with the Integer value of the year in the rowtag, MonthMenu will have the months from January to December in order, but in any language you like.

Dim d As New Date
d.year = YearMenu.RowTag(YearMenu.ListIndex)
d.month = MonthMenu.ListIndex + 2 // Actually want the month after the one selected which is zero based.
d.day = 1 // d now has the first day of the following month
d.day = d.day - 1 // d is now the last day of the selected month

DayMenu.DeleteAllRows
For i As Integer = 1 To d.day
DayMenu.Addrow Str(i)
Next

[quote=212484:@Wayne Golding]This doesn’t handle Leap years very well though. I prefer to use the date class to get the number of days in a month.

Assuming you have three popupmenus named YearMenu, MonthMenu & DayMenu. YearMenu will have a range of acceptable years with the Integer value of the year in the rowtag, MonthMenu will have the months from January to December in order, but in any language you like.

Dim d As New Date
d.year = YearMenu.RowTag(YearMenu.ListIndex)
d.month = MonthMenu.ListIndex + 2 // Actually want the month after the one selected which is zero based.
d.day = 1 // d now has the first day of the following month
d.day = d.day - 1 // d is now the last day of the selected month

DayMenu.DeleteAllRows
For i As Integer = 1 To d.day
DayMenu.Addrow Str(i)
Next[/quote]

That is by far the best way of doing it.

On the 17th i will probably be too tired and at the 18th i will travel home right after the conference ( about 4 hours).