lhgrappler
New member
- Local time
 - Today, 00:38
 
- Joined
 - May 22, 2019
 
- Messages
 - 13
 
I'm trying to make a button that will open a report filtered for last month.  I have been all over the internet and tried several different methods, everytime I end up with a type mismatch error.  Here's the lastest attempt:
Private Sub cmdMonthlyReports_Click()
Dim defDate1 As Date, defDate2 As Date
defDate1 = Date
defDate2 = Date
defDate1 = DateSerial(Year(DateAdd("m", -1, Date)), Month(DateAdd("m", -1, Date)), 1)
defDate2 = DateAdd("d", -1, DateSerial(Year(Date), Month(Date), 1))
Dim strDateRange As String
strDateRange = "Appointment >= # " & defDate1 & _
" # And Appointment < #" & defDate2 & "#"
DoCmd.OpenReport "Monthly Appointments", acViewReport, , strDateRange
End Sub
When it's not running - the DateSerial() function works as expected in the immediate window, during runtime it throws the type mismatch error.
Any help is appreciated. I have only dabbled in Access, I'm just helping my dad get his database easier for him to use (the guy who set it up is not available)
 Private Sub cmdMonthlyReports_Click()
Dim defDate1 As Date, defDate2 As Date
defDate1 = Date
defDate2 = Date
defDate1 = DateSerial(Year(DateAdd("m", -1, Date)), Month(DateAdd("m", -1, Date)), 1)
defDate2 = DateAdd("d", -1, DateSerial(Year(Date), Month(Date), 1))
Dim strDateRange As String
strDateRange = "Appointment >= # " & defDate1 & _
" # And Appointment < #" & defDate2 & "#"
DoCmd.OpenReport "Monthly Appointments", acViewReport, , strDateRange
End Sub
When it's not running - the DateSerial() function works as expected in the immediate window, during runtime it throws the type mismatch error.
Any help is appreciated. I have only dabbled in Access, I'm just helping my dad get his database easier for him to use (the guy who set it up is not available)
			
				Last edited: