Hi,
I am trying to create a function to read a value from against a record ID in a table. When I run the function within the query it does not run and the program hangs. This is what I am trying:
Table:
CLAIMREF SCRAPVALUE
1 1344
2 1315
3 2315
4 1215
5 1244
Function:
Function GetTSV(Claimref As Long) As Double
Dim db As Database
Dim Lrs As DAO.Recordset
Dim LSQL As String
Dim LGST As String
'Open connection to current Access database
Set db = CurrentDb()
'Create SQL statement to retrieve value from GST table
LSQL = "SELECT ScrapValue FROM QFS_Claims_backup2 WHERE [CLAIMREF] = '" & Claimref & "'"
Set Lrs = db.OpenRecordset(LSQL)
'Retrieve value if data is found
If Lrs.EOF = False Then
LGST = Lrs("ScrapValue")
Else
LGST = "Not found"
End If
Lrs.Close
Set Lrs = Nothing
GetTSV = LGST
End Function
-----------------------------------
Finally, I am using the GetTSV(ClaimNo) function to give me the value but it is failing without giving any error.
E.g. GetTSV(4)=1215 but I am not getting the right result. I am doing something wrong in the VBA code?
Please Help!!!
Regards,
Ashish