Solved Parameter Query

tonsos

New member
Local time
Today, 21:34
Joined
Jun 28, 2024
Messages
5
Hi, I have set up what I think is a simple parameter query....but for the life of me I don't now why it doesn't work. When I run the following select query
1719563109150.png


I get
1719563177847.png

All well and good.
When I do the following, and then type in "2"
1719563286399.png


I get
1719563344823.png


I'm stumped. It is the same issue even if it is 3, 4 etc
 
can you post a copy of the db with a few fictitious records to illustrate the problem
 
Val works just as well?
Code:
SELECT tblDOC_NUM.*, tblDOC_TYPE.PRE_SCRIPT, tblDOC_TYPE.Description, DateDiff("m",Date(),([Date Reviewed]+[Review Period (Months)]*30)) AS [Difference in Date]
FROM tblDOC_TYPE INNER JOIN tblDOC_NUM ON tblDOC_TYPE.[Document Type] = tblDOC_NUM.[Document Type]
WHERE (((DateDiff("m",Date(),([Date Reviewed]+[Review Period (Months)]*30)))<Val([How many months?])) AND ((tblDOC_TYPE.Active)=True))
ORDER BY tblDOC_NUM.[Document Type], tblDOC_NUM.[Document Number], tblDOC_TYPE.PRE_SCRIPT;
I think it was comparing alphabetically as the input was likely take as a string.?
1719577029723.png
 
Val works just as well?
Code:
SELECT tblDOC_NUM.*, tblDOC_TYPE.PRE_SCRIPT, tblDOC_TYPE.Description, DateDiff("m",Date(),([Date Reviewed]+[Review Period (Months)]*30)) AS [Difference in Date]
FROM tblDOC_TYPE INNER JOIN tblDOC_NUM ON tblDOC_TYPE.[Document Type] = tblDOC_NUM.[Document Type]
WHERE (((DateDiff("m",Date(),([Date Reviewed]+[Review Period (Months)]*30)))<Val([How many months?])) AND ((tblDOC_TYPE.Active)=True))
ORDER BY tblDOC_NUM.[Document Type], tblDOC_NUM.[Document Number], tblDOC_TYPE.PRE_SCRIPT;
I think it was comparing alphabetically as the input was likely take as a string.?
View attachment 114802
Ahhhhh
 
[Date Reviewed]+[Review Period (Months)]*30

Assuming [Date Reviewed] is a date, you are adding some number of days, NOT months to it. If you want to add months, you MUST use dateAdd(). Because SomeDate + SomeInteger assumes the second addend is days.

Also, using embedded spaces and special characters in your names is really hard to read AND forces you to use [] constantly to enclose the badly formated names so that they stop offending VBA.
 

Users who are viewing this thread

Back
Top Bottom