flyinghippo99
Registered User.
- Local time
- Today, 03:31
- Joined
- Feb 28, 2011
- Messages
- 53
Hi All,
I'm not sure where to put this question - forms, VBA, or query. So I put it here.
So, I'm trying to display data that is in "percent" format in Textboxes on a form using a DLookUp of a query.
Each textbox on the form has the following VBA code as its ControlSource:
=IIf(DLookUp("[Concentration Business Relationships]","[QryMetric120055Combine]","[MetricDate]=" & [Forms]![FrmDataValidationAdvisorMetrics1]![MonthT5])=-0.001,"na",IIf(DLookUp("[Concentration Business Relationships]","[QryMetric120055Combine]","[MetricDate]=" & [Forms]![FrmDataValidationAdvisorMetrics1]![MonthT5])=-0.002,"nr",DLookUp("[Concentration Business Relationships]","[QryMetric120055Combine]","[MetricDate]=" & [Forms]![FrmDataValidationAdvisorMetrics1]![MonthT5])))
Don't mind the names etc. It's just the sample. The logic here is simple. If the underlying data has -0.001 then display "na". If the underlying data has -.002 then display "nr". All else display the underlying data. Now, the underlying data is in
a query called QryMetric120055Combine(just naming convention).
Now, this VBA code above works for ALL data types(currency$, standard, etc.) but it fails for percent data. Why?
Note: All other data types are in a different query i.e. other than QryMetric120055Combine.
Here's what QryMetric120055Combine looks like:
SELECT MetricDate, FormatPercent(PercentCol,3) AS [Concentration Business Relationships]
FROM MetricValueTbl
WHERE (KeyNum=120055);
I used the FormatPercent function so that at least it shows the right amount of digits like -.001% or -.002%(but this imply that underlying data is -.00001 and -.00002).
The reason I had to use FormatPercent is because before I used the plain vanilla
Percent it was just showing 100% or 0%.
Anyhow, the DLookUp above doesn't work. It's showing #Error message in each of the textboxes instead of 2.3% , na, na, .9%, etc.
I even tried to play around with the VBA logic above so that instead of introducing the additional logic check for -.001 or -.002 and just :
DLookUp("[Concentration Business Relationships]","[QryMetric120055Combine]","[MetricDate]=" & [Forms]![FrmDataValidationAdvisorMetrics1]![MonthT5])
And it gave me 0.000% instead of -.001%. Reducing it to the simplest case here.
I'm not sure where to put this question - forms, VBA, or query. So I put it here.
So, I'm trying to display data that is in "percent" format in Textboxes on a form using a DLookUp of a query.
Each textbox on the form has the following VBA code as its ControlSource:
=IIf(DLookUp("[Concentration Business Relationships]","[QryMetric120055Combine]","[MetricDate]=" & [Forms]![FrmDataValidationAdvisorMetrics1]![MonthT5])=-0.001,"na",IIf(DLookUp("[Concentration Business Relationships]","[QryMetric120055Combine]","[MetricDate]=" & [Forms]![FrmDataValidationAdvisorMetrics1]![MonthT5])=-0.002,"nr",DLookUp("[Concentration Business Relationships]","[QryMetric120055Combine]","[MetricDate]=" & [Forms]![FrmDataValidationAdvisorMetrics1]![MonthT5])))
Don't mind the names etc. It's just the sample. The logic here is simple. If the underlying data has -0.001 then display "na". If the underlying data has -.002 then display "nr". All else display the underlying data. Now, the underlying data is in
a query called QryMetric120055Combine(just naming convention).
Now, this VBA code above works for ALL data types(currency$, standard, etc.) but it fails for percent data. Why?
Note: All other data types are in a different query i.e. other than QryMetric120055Combine.
Here's what QryMetric120055Combine looks like:
SELECT MetricDate, FormatPercent(PercentCol,3) AS [Concentration Business Relationships]
FROM MetricValueTbl
WHERE (KeyNum=120055);
I used the FormatPercent function so that at least it shows the right amount of digits like -.001% or -.002%(but this imply that underlying data is -.00001 and -.00002).
The reason I had to use FormatPercent is because before I used the plain vanilla
Percent it was just showing 100% or 0%.
Anyhow, the DLookUp above doesn't work. It's showing #Error message in each of the textboxes instead of 2.3% , na, na, .9%, etc.
I even tried to play around with the VBA logic above so that instead of introducing the additional logic check for -.001 or -.002 and just :
DLookUp("[Concentration Business Relationships]","[QryMetric120055Combine]","[MetricDate]=" & [Forms]![FrmDataValidationAdvisorMetrics1]![MonthT5])
And it gave me 0.000% instead of -.001%. Reducing it to the simplest case here.