A
Arvi Laanemets
Hi
I have an UDF, which is called from query:
***
Public Function ORnk(SourceN As String, KeyN As String, FieldN As String,
FieldVal, YearVal As Integer, GroupVal As Integer) As String
Dim dbs2 As Database
Dim rs2 As Recordset
Set dbs2 = CurrentDb
On Error GoTo Err_ORnk
Set rs2 = dbs2.OpenRecordset("SELECT " & KeyN & ", " & FieldN & _
" FROM " & SourceN & _
" WHERE Aasta = " & YearVal & " AND Grupp = " & GroupVal & _
" Order By 2 DESC")
rs2.FindFirst "[" & FieldN & "] = " & FieldVal
FFnd = Nz(rs2.AbsolutePosition, 0) + 1
i = -1
While Nz(rs2.Fields(1), 0) = FieldVal
i = i + 1
LFnd = FFnd + i
rs2.MoveNext
ORnk = CStr(FFnd) & IIf(FFnd = LFnd, "", "-" & CStr(LFnd))
Wend
Err_ORnk:
rs2.Close
dbs2.Close
Set rs2 = Nothing
Set dbs2 = Nothing
End Function
***
The function returns ranking for field FieldN in table/query SourceN for
particular year and group. The ranking is a string like "1" or "3 - 5" etc.
But the function fails for all cases with non-integer FieldVal, when in
Window's settings the decimal separator is set to ',' instead of '.' The
problem arrives at row
rs2.FindFirst "[" & FieldN & "] = " & FieldVal
Access simply doesn't find any match whenever the FieldVal isn't integer,
and the function is ended at spot. I tried to declare VieldVal in function
as Double or Variant parameter, but it didn't help.
I avoided the problem at moment by resetting the decimal separator for my
computer to period, but later I have to deliver my database to another user,
where such setup isn't allowed. Has somebody here encoutered a similar
problem, and is there some cure for it?
I have an UDF, which is called from query:
***
Public Function ORnk(SourceN As String, KeyN As String, FieldN As String,
FieldVal, YearVal As Integer, GroupVal As Integer) As String
Dim dbs2 As Database
Dim rs2 As Recordset
Set dbs2 = CurrentDb
On Error GoTo Err_ORnk
Set rs2 = dbs2.OpenRecordset("SELECT " & KeyN & ", " & FieldN & _
" FROM " & SourceN & _
" WHERE Aasta = " & YearVal & " AND Grupp = " & GroupVal & _
" Order By 2 DESC")
rs2.FindFirst "[" & FieldN & "] = " & FieldVal
FFnd = Nz(rs2.AbsolutePosition, 0) + 1
i = -1
While Nz(rs2.Fields(1), 0) = FieldVal
i = i + 1
LFnd = FFnd + i
rs2.MoveNext
ORnk = CStr(FFnd) & IIf(FFnd = LFnd, "", "-" & CStr(LFnd))
Wend
Err_ORnk:
rs2.Close
dbs2.Close
Set rs2 = Nothing
Set dbs2 = Nothing
End Function
***
The function returns ranking for field FieldN in table/query SourceN for
particular year and group. The ranking is a string like "1" or "3 - 5" etc.
But the function fails for all cases with non-integer FieldVal, when in
Window's settings the decimal separator is set to ',' instead of '.' The
problem arrives at row
rs2.FindFirst "[" & FieldN & "] = " & FieldVal
Access simply doesn't find any match whenever the FieldVal isn't integer,
and the function is ended at spot. I tried to declare VieldVal in function
as Double or Variant parameter, but it didn't help.
I avoided the problem at moment by resetting the decimal separator for my
computer to period, but later I have to deliver my database to another user,
where such setup isn't allowed. Has somebody here encoutered a similar
problem, and is there some cure for it?