I have a query on a linked table that I'm trying to open the results for. I was using DoCmd.SetParameter to set filter the results of the OpenQuery. I've used this before on another table, and it worked fine. For some reason though, I can't get this to return any results.
My code is as follows:
Dim ReportDate As Date
Dim strReportDate As String
ReportDate = DateValue(Me.FromDate.Value)
strReportDate = Format(ReportDate, "mm-dd-yyyy")
DoCmd.SetParameter "Enter ShipDate", strReportDate
DoCmd.OpenQuery "TrackingDataQuery", acViewNormal, acReadOnly
(The format is there because originally, I was checking against the date field in my query, and thought perhaps there was an issue there, so I created a calculated field in the query that takes that field and does the same format on it.)
The thing that's really confusing me, is if I just run the query, it will ask me for the criteria as it should, and if I put in the date (in the "mm-dd-yyyy" format as above), it gives me the proper result set.
sql for the query (right now) is (I've also tried this with just the actual ShipDate field, just using the DateValue conversion (and adjusting the above as well). IN the linked SQL table, ShipDate is a datetime type:
SELECT dbo_TrackingData.PackageID, dbo_TrackingData.TrackingNo,
dbo_TrackingData.ShipDate, dbo_TrackingData.weight, dbo_TrackingData.Ref1,
dbo_TrackingData.Ref2, dbo_TrackingData.Ref5,
Format(DateValue([ShipDate]),"mm-dd-yyyy") AS strShipDate
FROM dbo_TrackingData
WHERE (((Format(DateValue([ShipDate]),"mm-dd-yyyy"))=[Enter ShipDate]));
This should work:
Dim strReportDate As String
strReportDate = "#" & Format(Me!FromDate.Value, "yyyy\/mm\/dd") & "#"
DoCmd.SetParameter "Enter ShipDate", strReportDate
DoCmd.OpenQuery "TrackingDataQuery", acViewNormal, acReadOnly
with this SQL:
SELECT
dbo_TrackingData.PackageID, dbo_TrackingData.TrackingNo,
dbo_TrackingData.ShipDate, dbo_TrackingData.weight, dbo_TrackingData.Ref1,
dbo_TrackingData.Ref2, dbo_TrackingData.Ref5
FROM
dbo_TrackingData
WHERE
[ShipDate] = [Enter ShipDate];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With