Dim RCPTSetUp, FilterString As String
RCPTSetUp = Me.ReceiptSetUp
FilterString = " WHERE "
'good trick from DBGuy to check if textbox is null or empty string. it adds an empty string to the textbox, then checks if the total = empty string.
If Me.FundFilterAndGroup & "" <> "" Then
FilterString = FilterString & "FundId = " & Me.FundFilterAndGroup & " And "
Else
End If
If Me.ContactFilter & "" <> "" Then
FilterString = FilterString & "ContactID =" & Me.ContactFilter & " And "
Else
End If
If Me.AmountFilter & "" <> "" Then
'sets the amount filter according to the set up chosen,
If RCPTSetUp = 1 Then
FilterString = FilterString & "AdditionAmount >= " & Me.AmountFilter & " And "
ElseIf RCPTSetUp = 2 Then
FilterString = FilterString & "RunningContactTotalDates >= " & Me.AmountFilter & " And "
ElseIf RCPTSetUp = 3 Then
FilterString = FilterString & "RunningFund_ContactTotalDates >= " & Me.AmountFilter & " And "
Else
End If
If Me.FromFilter & "" <> "" Then
FilterString = FilterString & "TransactionDate >= #" & Me.FromFilter & "# And "
Else
End If
If Me.ToFilter & "" <> "" Then
FilterString = FilterString & "TransactionDate <= #" & Me.ToFilter & "# And "
Else
End If
End If
Me.QueryString = FilterString
'cut of the extra " And " at the end of the filterstring, use CutEndOfString Function created by YitzchokKupetz DataCharts 4/30/20
FilterString = CutEndOfString(FilterString, 5)
'check if filterstring is empty but has the word "WHERE", make it null.
If FilterString = "Where" Then
FilterString = Null
End If
Me.QueryString = FilterString
' If an error occurs, jump down to the DataAccessError section.
On Error GoTo DataAccessError
' Create a SELECT command.
Dim Query1
Query1 = "SELECT TDID, ContactID, TransactionDate, AdditionAmount, FundId, SpecialReceipt, RunningFund_ContactTotalDates, RunningContactTotalDates, ReceiptNumber From ReceiptsToCreateTotals_Dates " _
& FilterString _
'for set up and testing only - shows the Query String in text box on form
Me.QueryString = Query1
' Get a recordset using this command.
Dim rs
Set rs = fDAOGenericRst(Me.QueryString)
Dim ReceiptNum, DonationID, Donor, Fund, Special
ReceiptNum = DLookup("startNumber", "ReceiptNumbers")
DonationID = rs("TDID")
Donor = rs("ContactID")
Fund = rs("FundID")
Special = rs("SpecialReceipt")
' Move through the recordset, looking at each record.
' Each record is a separate Donation.
Do Until rs.EOF
'code for Seperate receipts for each fund for each contact
If rs!ContactID <> Donor Or rs!FundId <> Fund Then
ReceiptNum = ReceiptNum + 1
End If
' For each Donation, get the Donation ID.
'This is needed in order that the update command shouldn't update all records at once
'after creating this variable we will be able to add cretiria to the update command to only update this individuale record
'and on the next time around the next record
DonationID = rs("TDID")
Donor = rs("ContactID")
Fund = rs("FundID")
Dim UpdateCommand
UpdateCommand = "UPDATE TransactionDetails SET ReceiptNumber = ' " & ReceiptNum & " ' " & "WHERE TDID =" & DonationID
' Run the command.
CurrentDb.Execute UpdateCommand
' Move to the next Donation (if there is one).
rs.MoveNext
Loop
rs.Close
CurrentDb.Close
Exit Sub
DataAccessError:
' You only get here if an error occured.
' Show the error.
MsgBox Err.Description
' Try to clean up.
On Error Resume Next
'Recordset.Close
'CurrentDb.Close
End Sub