简体   繁体   中英

Access database Query Enter Parameter Value not working

I have the following query where statement in an access database:

WHERE (((IIf([MinOfDueDayMin]<0,0,Int([MinOfDueDayMin]/7)+1))<[EnterValue]) AND ((tblEquipment.Retired)=False))

The intent is to ask the user for a value and when the formula ----((IIf([MinOfDueDayMin]<0,0,Int([MinOfDueDayMin]/7)+1))---- is less than the user input when prompted with [EnterValue] . If I use a number like 52 instead of the [EnterValue] I get the correct results but when I keep the [EnterValue] I get the prompt and when I enter 52 I get results that are not less than 52. I actually get all the results as if the criteria was not there. However when I put in 10 when prompted instead of 52 I get the correct results.

The formula is in my results

IIf([MinOfDueDayMin]<0,0,Int([MinOfDueDayMin]/7)+1) AS Wks

so it displays the results.

You need to convert the user input to the numeric value. Use the Val() function for this:

IIf([MinOfDueDayMin]<0,0,Int([MinOfDueDayMin]/7)+1))<Val([EnterValue])

You can also specify the data type for the parameter. This article shows you how:

To specify the data type for parameters in a query:

  1. With the query open in Design view, on the Design tab, in the Show/Hide group, click Parameters.

  2. In the Query Parameters box, in the Parameter column, enter the prompt for each parameter you want to specify a data type for. Make sure that each parameter matches the prompt that you used in the Criteria row of the query design grid.

  3. In the Data Type column, select the data type for each parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM