My database uses an append query to add member financial records for current members when a new financial year is established - launched from a command button on a form to manage financial years. Following in the same routine are two update queries that then insert the membership fee appropriate to the member type (1 = an person, 2 = corporate member) for that financial year. However it fails with the above message when it gets to the first of these two update queries. The update queries are each dependent upon a select query that when run, retrieves and shows the appropriate fees for the financial year for the member type. The select query also uses the financial year value from the form.
The select query uses the SQL:
SELECT FinancialMbr.FinMbrID, FinancialMbr.MemberID, IIf(IsNull([MembershipFee]),IIf([MbrTypeID]=1,[Fee],[CorpFee]),[MembershipFee]) AS FeeOwed, FinancialMbr.FinYrID, Member.MbrTypeID
FROM tluFinYr INNER JOIN (Member RIGHT JOIN FinancialMbr ON Member.MemberID = FinancialMbr.MemberID) ON tluFinYr.FinYrID = FinancialMbr.FinYrID
WHERE (((FinancialMbr.FinYrID)=[Me]![FinYrID]) AND ((Member.MbrTypeID)=1));
The code for the command button is as below. It fails at line 47. Appreciate any advice/pointers to what can/should be done:
The select query uses the SQL:
SELECT FinancialMbr.FinMbrID, FinancialMbr.MemberID, IIf(IsNull([MembershipFee]),IIf([MbrTypeID]=1,[Fee],[CorpFee]),[MembershipFee]) AS FeeOwed, FinancialMbr.FinYrID, Member.MbrTypeID
FROM tluFinYr INNER JOIN (Member RIGHT JOIN FinancialMbr ON Member.MemberID = FinancialMbr.MemberID) ON tluFinYr.FinYrID = FinancialMbr.FinYrID
WHERE (((FinancialMbr.FinYrID)=[Me]![FinYrID]) AND ((Member.MbrTypeID)=1));
The code for the command button is as below. It fails at line 47. Appreciate any advice/pointers to what can/should be done:
Code:
Private Sub btnFinYrMbrRec_Click()
Dim AFRFManagement As DAO.Database
Dim qdf As DAO.QueryDef
Dim dtFinYrStartDate, dtFinYrEndDate As Date
Dim lngRowsAffected As Long
' Dim intMemberTypeID As Integer
Dim intFinYrID As Integer
Set AFRFManagement = CurrentDb
dtFinYrStartDate = Me!FinYrStartDate
dtFinYrEndDate = Me!FinYrEndDate
intFinYrID = Me!FinYrID
Set qdf = CurrentDb.QueryDefs("qryMbr4FinYrUpdate")
qdf!setFinYrID = intFinYrID
qdf!FinYrEndDate = dtFinYrEndDate
qdf!FinYrStartDate = dtFinYrStartDate
If IsNull(intFinYrID) Then
MsgBox "No Financial Year ID"
Else
If IsNull(dtFinYrEndDate) Then
MsgBox "No Financial Year End Date"
Else
If IsNull(dtFinYrStartDate) Then
MsgBox "No Financial Year Start Date"
Else
If DCount("[FinYrID]", "FinancialMbr", "[FinYrID]=" & intFinYrID) > 0 Then
MsgBox "Records already exist for the financial year - verify if the records are valid or remove them"
Else
qdf.Execute
lngRowsAffected = AFRFManagement.RecordsAffected
Set qdf = Nothing
MsgBox "Completed - Financial Records of " & lngRowsAffected & " members for the selected Financial Year Added"
' lngRowsAffected = 0 ' Reset counter
'Now Update records with applicable fees (Membership Fee - Corporate or individual)
' intMemberTypeID = 1 ' Members who are natural persons
AFRFManagement.Execute " UPDATE FinancialMbr SET FinancialMbr.MembershipFee = [qryMbrFeePerson]![FeeOwed]" & _
"WHERE(((FinancialMbr.FinMbrID) = [qryMbrFeePerson]![FinMbrID]))"
lngRowsAffected = AFRFManagement.RecordsAffected
MsgBox "Updated fees for " & lngRowsAffected & " Individual Members within the Financial Year"
' lngRowsAffected = 0 ' Reset Counter
' intMemberTypeID = 2 ' for corporate mambers
AFRFManagement.Execute "UPDATE FinancialMbr SET FinancialMbr.MembershipFee = [qryMbrFeeOrg]![FeeOwed]" & _
"WHERE (((FinancialMbr.FinMbrID)=[qryMbrFeePerson]![FinMbrID]))"
MsgBox "Update fees for " & lngRowsAffected & " Corporate Members within the Financial Year"
' lngRowsAffected = 0 ' Reset Counter
End If
End If
End If
End If
End Sub