Search code examples
vbams-access

Is there a way to use a variable/combo box to select a year in a date without using date picker


I am working on a calculator to track my (and my coworkers may use it) overtime at work. We have a bunch written in excel, but I am trying to do one in access. There is probably a simple solution, but having searched for a couple days for using a variable in a date has only given me how to use the date as a variable. So our pay periods are defined 1/1/yyyy to 1/15/yyyy etc. Hour pay is calculated on the number of days we have in a pay period which varies every year by days off. I have it calculating the proper number of days using VBA, but I am having difficulty getting it to use the combo box year which defaults to current year.

I have tried setting the control source to = 01/01/[cmbYearselect]

using variables, creating a string in vba and format date

Any help would be appreciated as I am going to have to use the variable in both the control sources and vba code.

Thank you

01/01/[cmbYearSelect] results in 12/30/1899 on my form

everything else has resulted in a type mismatch for the variables etc.


Solution

  • Use CDate with no year:

    =CDate(#01/01#)
    

    or:

    =CDate("01/01")
    

    to have primo of the current year.