Forum Discussion

nicoleethier's avatar
nicoleethier
Copper Contributor
May 21, 2026

Access selecting specific date on a calendar

I'm pulling my hair out because everything I've found through my research says my VBA code should work, but it doesn't!

Here's the story. I have a calendar (form) that shows events going on for each month. What I want is for a person to click on a specific day and have a pop-up form appear showing more details of the events for whatever day they clicked on. I used the below code, which mostly works... When I click on a date, the month and year will be correct, but not the day of the month. The day of the month is always today's day. For example, let's say I click on the day Feb. 2, 2024 and today's date is May 21, 2026. My pop-up form will show the events for Feb. 21, 2024.

 

This is the code I have:

Private Sub lblTue3_Click()

Dim txtSelectDate As Date (probably don't need this)

Dim iDayOfMonth As Integer

Dim iMonth As Integer

Dim iYear As Integer

Dim dSelectDate as Date



iDayOfMonth= Format(Me.txtSelectDate.Value, "d")

iMonth = Format(Me.txtSelectDate, "mm")

iYear = Format(Me.txtSelectDate, "yyyy")



dSelectDate = CDate(iMonth & "/" & iDayOfMonth & "/" & iYear)

DoCmd.OpenForm "frmThatContainsMyData", acNormal, , "[DateOnFormUsedForFilter]=#" & dSelectDate & "#", , acDialog

 

Instead of Format, I've tried using the code Day(Me.txtSelectDate), but that didn't work either. It always defaults to the day of the month that's today.

Can anyone tell what I'm doing wrong? I've checked the formatting, and everything is set to 'Short Date'... I'm just at a complete loss!

Any help is greatly appreciated!

No RepliesBe the first to reply