Hi Forum,
Have had issues with Null's in VBA code and wonder if the following can be used to avoid some of these occurrences.
This Code finds a matching record in a table.
Can we put this, or similar, ahead of the next code so that if a record exits, the 2nd code is actioned and if no record exits, then GetMemPointsTraded = 0.
Appreciate any guidance
Have had issues with Null's in VBA code and wonder if the following can be used to avoid some of these occurrences.
This Code finds a matching record in a table.
Code:
Private Sub ADPK_AfterUpdate()
Dim DB As Database, TData As Recordset
Dim ADPK As Integer
ADPK = Me.ADPK
Set DB = DBEngine.Workspaces(0).Databases(0)
Set TData = DB.OpenRecordset("TblPointsTraded", DB_OPEN_TABLE)
TData.Index = "MemberADPK"
TData.Seek "=", ADPK
If Not TData.NoMatch Then
MsgBox TData![MemberADPK]
End If
TData.Close
End Sub
Code:
Public Function GetMemPointsTraded(RecordID As Variant) As Long
'RecordID is the Control Value on the Form or Report
Dim rst As DAO.Recordset
Dim sqlString As String
'Points Earned Single Loan on Report or Form
sqlString = "SELECT Sum(ClubPointsTraded) AS Traded " & _
"FROM TblPointsTraded " & _
"WHERE (((ADPK)=" & RecordID & "));"
Set rst = CurrentDb.OpenRecordset(sqlString)
If rst.RecordCount <> 0 Then
'Assign SQL result to Variable
GetMemPointsTraded = rst!Traded
Else
GetMemPointsTraded = 0
End If
rst.Close
Set rst = Nothing
End Function

Last edited: