Run-time error'3464'

  • Thread starter Thread starter randria
  • Start date Start date
R

randria

Hello,
I have a query based report and the following code to open the report

Private Sub Ctl2doCmd_Click()
Dim strDoc As String
Dim strLink As String

strDoc = "2do"
strLink = " [Due Date] Between " & CLng(Me![Date3]) & " AND " &
CLng(Me![Date4])

DoCmd.OpenReport strDoc, acViewPreview, , strLink

I get the above error msg (Data type mismatch ) while [Due Date],[Date3] and
[Date4] have date data type.

Please help, what am I doing wrong ?
Many thanks.
 
The CLng converts them into a number so they are no longer a date. Maybe you
meant CDate.
 
Thanks Jerry, that got rid of the error 3464 however the query did not return
any record. Here is the correction I made based on your suggestion

strDoc = "2do"
strLink = "[Due Date] Between " & CDate(Me![Date3]) & " AND " &
CDate(Me![Date4])

I tried to put this directly in the criteria of the query: Between
([Forms]![myfrm]![Date3]) And ([Forms]![myfrm]![Date4]), using a new command
btn , the report opened with Data. I cant understand what is wrong with above
code.
Many thanks.
Jerry Whittle said:
The CLng converts them into a number so they are no longer a date. Maybe you
meant CDate.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

randria said:
Hello,
I have a query based report and the following code to open the report

Private Sub Ctl2doCmd_Click()
Dim strDoc As String
Dim strLink As String

strDoc = "2do"
strLink = " [Due Date] Between " & CLng(Me![Date3]) & " AND " &
CLng(Me![Date4])

DoCmd.OpenReport strDoc, acViewPreview, , strLink

I get the above error msg (Data type mismatch ) while [Due Date],[Date3] and
[Date4] have date data type.

Please help, what am I doing wrong ?
Many thanks.
 
You need to delimit date literals with the # character.

strLink = "[Due Date] Between #" & CDate(Me![Date3]) & "# AND #" &
CDate(Me![Date4]) & "#")

Another problem is if you are not in the US then you probably need to
force the date format into either the US format of m/d/y or my
preference of yyyy mm dd format.

strLink = "[Due Date] Between #" & Format(Me![Date3],"yyyy-mm-dd") & "#
AND #" & Format(Me![Date4],"yyyy-mm-dd") & "#")


'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

Thanks Jerry, that got rid of the error 3464 however the query did not return
any record. Here is the correction I made based on your suggestion

strDoc = "2do"
strLink = "[Due Date] Between " & CDate(Me![Date3]) & " AND " &
CDate(Me![Date4])

I tried to put this directly in the criteria of the query: Between
([Forms]![myfrm]![Date3]) And ([Forms]![myfrm]![Date4]), using a new command
btn , the report opened with Data. I cant understand what is wrong with above
code.
Many thanks.
Jerry Whittle said:
The CLng converts them into a number so they are no longer a date. Maybe you
meant CDate.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

randria said:
Hello,
I have a query based report and the following code to open the report

Private Sub Ctl2doCmd_Click()
Dim strDoc As String
Dim strLink As String

strDoc = "2do"
strLink = " [Due Date] Between " & CLng(Me![Date3]) & " AND " &
CLng(Me![Date4])

DoCmd.OpenReport strDoc, acViewPreview, , strLink

I get the above error msg (Data type mismatch ) while [Due Date],[Date3] and
[Date4] have date data type.

Please help, what am I doing wrong ?
Many thanks.
 
Thank you both Jerry and John for your helps, it is now working fine. I was
really puzzled because I have used my first code ( using CLng ) somewhere
else and it works fine. I just can t figure out at what condition it does not
work, the main thing is it is working now.

Many thanks.

John Spencer said:
You need to delimit date literals with the # character.

strLink = "[Due Date] Between #" & CDate(Me![Date3]) & "# AND #" &
CDate(Me![Date4]) & "#")

Another problem is if you are not in the US then you probably need to
force the date format into either the US format of m/d/y or my
preference of yyyy mm dd format.

strLink = "[Due Date] Between #" & Format(Me![Date3],"yyyy-mm-dd") & "#
AND #" & Format(Me![Date4],"yyyy-mm-dd") & "#")


'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

Thanks Jerry, that got rid of the error 3464 however the query did not return
any record. Here is the correction I made based on your suggestion

strDoc = "2do"
strLink = "[Due Date] Between " & CDate(Me![Date3]) & " AND " &
CDate(Me![Date4])

I tried to put this directly in the criteria of the query: Between
([Forms]![myfrm]![Date3]) And ([Forms]![myfrm]![Date4]), using a new command
btn , the report opened with Data. I cant understand what is wrong with above
code.
Many thanks.
Jerry Whittle said:
The CLng converts them into a number so they are no longer a date. Maybe you
meant CDate.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

:

Hello,
I have a query based report and the following code to open the report

Private Sub Ctl2doCmd_Click()
Dim strDoc As String
Dim strLink As String

strDoc = "2do"
strLink = " [Due Date] Between " & CLng(Me![Date3]) & " AND " &
CLng(Me![Date4])

DoCmd.OpenReport strDoc, acViewPreview, , strLink

I get the above error msg (Data type mismatch ) while [Due Date],[Date3] and
[Date4] have date data type.

Please help, what am I doing wrong ?
Many thanks.
 
Back
Top