
Originally Posted by
stupesek
I perhaps was a little to simple in the original post. Here is the test code I am working with.
Option Compare Database
Option Explicit
Function Interpertation() As String
If [AnalysisName] = 66 Then
Interpertation = "Works" 'this line just to test if I can put a phrase in the text box when analysis is nitrate
Else 'Go to next evaluation
End Function
As is I get the Name? error when the code is part of the report's module code.
AnalysisName is a interger field linking a look-up table with all the analysis parameters.
I will have several such evaluations in the final code that will basically say "If AnalysisName = something and Result is > or< or = to something else then Interpretation = some sort of text.
What I don't know is how to get the report module code to show up in the text box without the name? error. I can get text to show up when the code is in a module by itself and it becomes a function in the Expression Builder, but it doesn't evaluate properly. Everyone of my lines returns the same text despite a change in the Analysis Name.
Where is [AnalysisName]?
Do you have a control on the form withe the name [AnalysisName] or a field in the reccord source for the report?
What is the Data Type for [AnalysisName] ?
Your code is expecting [AnalysisName] to be a numeric data type. Is the correct?
To use a function you should pass an argument and then return something.
Code:
Function fInterpertation(pstrAnalysisName as Long) As String
If pstrAnalysisName = 66 Then
fInterpertation = "Works" 'this line just to test if I can put a phrase in the text box when analysis is nitrate
Else 'Go to next evaluation
End Function
IOn the report use a text box that is NOT named AnalysisName. i would use txtAnalysisName
then you can set the control source to be:
Code:
=fInterpertation([AnalysisName])
TIP: Please use the code tags when posting code to make it readable.
I would also urge you to be explicit with your references. Example use Me., etc.
I would also suggest using a Select Case statement like this
Code:
Function fInterpertation(pstrAnalysisName as Long) As String
Select Case pstrAnalysisName
Case 66
fInterpertation = "Works 66"
Case 67
fInterpertation = "Works 67"
Case Else
fInterpertation = "Unknown"
End Select
End Function