F
Forgone
Hi everyone,
I'm hoping that what I'm trying to achieve is possible and I am not
sure that it can and couldn't find the answer.
I originally wrote a custom function to perform a DLOOKUP and return
the results which is used in a query and then started writing another
function to do almost the same DLOOKUP job but rather than returning
the "cost code" it would return the "cost code description". Thus,
why I thought having a function that would return both values as an
array would be even better but not so sure.
The original function was:
-------
Public Function LookupSun(Costcode As String) As Variant
Dim LookupSunY, LookupSunZ, VarX, VarY, VarZ As Variant
VarX = Mid(Costcode, 4, 5)
VarY = DLookup("[COST_CENTRE_SUN]", "SUNCODES", "[COST_CODE_SUN_CODE]
= '" & VarX & "'")
VarZ = DLookup("[COST_CENTRE_SUN_DESCRIPTION]", "SUNCODES",
"[COST_CODE_SUN_CODE] = '" & VarX & "'")
If Not IsNull(VarY) Then
LookupSunY = VarY
Else
LookupSunY = "ERROR - No Code Found"
End If
If Not IsNull(VarZ) Then
LookupSunZ = VarZ
Else
LookupSunZ = "ERROR - No Code Found"
End If
LookupSun = Array(LookupSunY, LookupSunZ)
End Function
-------
The problem is that I'm sure that the DLOOKUP functions work but then
I realised that the problem is that as I have to tell the function
what data to use, how would I go about telling the query which value
to use.
EG: Expr1:=LookupSun([Costcode],(1) as the array functions are in the
format of =LookupSun(1) or =LookupSun(2)
I thought it would be much easier to have the 1 function do the
calculations and I can refer to it in the query.
I'm hoping that what I'm trying to achieve is possible and I am not
sure that it can and couldn't find the answer.
I originally wrote a custom function to perform a DLOOKUP and return
the results which is used in a query and then started writing another
function to do almost the same DLOOKUP job but rather than returning
the "cost code" it would return the "cost code description". Thus,
why I thought having a function that would return both values as an
array would be even better but not so sure.
The original function was:
-------
Public Function LookupSun(Costcode As String) As Variant
Dim LookupSunY, LookupSunZ, VarX, VarY, VarZ As Variant
VarX = Mid(Costcode, 4, 5)
VarY = DLookup("[COST_CENTRE_SUN]", "SUNCODES", "[COST_CODE_SUN_CODE]
= '" & VarX & "'")
VarZ = DLookup("[COST_CENTRE_SUN_DESCRIPTION]", "SUNCODES",
"[COST_CODE_SUN_CODE] = '" & VarX & "'")
If Not IsNull(VarY) Then
LookupSunY = VarY
Else
LookupSunY = "ERROR - No Code Found"
End If
If Not IsNull(VarZ) Then
LookupSunZ = VarZ
Else
LookupSunZ = "ERROR - No Code Found"
End If
LookupSun = Array(LookupSunY, LookupSunZ)
End Function
-------
The problem is that I'm sure that the DLOOKUP functions work but then
I realised that the problem is that as I have to tell the function
what data to use, how would I go about telling the query which value
to use.
EG: Expr1:=LookupSun([Costcode],(1) as the array functions are in the
format of =LookupSun(1) or =LookupSun(2)
I thought it would be much easier to have the 1 function do the
calculations and I can refer to it in the query.