Automatic data insertion - personal finance database

Luthius

Active Member
Joined
Apr 5, 2011
Messages
324
I would like to have an automatic insertion on my financial transactions based on a check box.
What I mean - On my tblFinanceTransaction table I have a YES/NO field called FixedExpense. When I have a fixed expense I mark the check-box on userform. I would like a way to automatic generate the same expense for the next month when the expense is closed (paid) like a copy of the expense but with next month date.

Fixed expenses are internet services, lighting, insurance, etc.

Just summarizing the table fields below:

tblFinanceTransaction
  • TrID (PK)
  • TrDate (Date)
  • Description (Text)
  • CrValue (Currency)
  • FixedExpense (Yes/No)
  • TrStatus (Yes/No)

Luthius
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
On a button of my userform I would like to pay all expenses based on a startDate and EndDate of my userform when I press the buttom.
Code:
strCriteria="like TrDate between #" & Format(Me.dtStart, "mm/dd/yyyy") & "# and #" & Format(Me.dtEnd, "mm/dd/yyyy") & "#;"

To pay based on criteria I can use the statement
Code:
strSQLUpdate="UPDATE tblFinanceTransaction SET tblFinanceTransaction.TrStatus = True WHERE " & strCriteria
But it pays all and don't generate for the next month a new fixed expense.

I was thinking on some algorithm that works this way.

#Open the record Set
#Identify what is fixed expense
#Clone the record adding future date using the function dateAdd
#Update the record
#Move Next
#

I don't know how to clone and use the record set.
I just scratch the SQL statement below - But it is not useful because it doesn't use proper criteria.

Code:
Dim strSQL As StringDim rs As Recordset
strSQL = "INSERT INTO tblFinanceTransaction ( TrDate, Description, CrValue, FixedExpense, TrStatus )" _
         & "SELECT DateAdd('m',1,[TrDate])as nextMonthDate, Description, CrValue, FixedExpense, TrStatus FROM tblFinanceTransaction;"

How can I create it?
 
Last edited:
Upvote 0
Solved using the algorithm.

Code:
Dim strSQL As String
Dim strCriteria As String
Dim rs As Recordset


strCriteria = "like TrDate between #" & Format(Me.dtStart, "mm/dd/yyyy") & "# and #" & Format(Me.dtEnd, "mm/dd/yyyy") & "#;"
rsSQL = "SELECT * FROM tblFinanceTransaction WHERE " & strCriteria


For i = 1 To rs.RecordCount
    strSQL = "INSERT INTO tblFinanceTransaction (TrDate, Description, CrValue, FixedExpense, TrStatus )" _
    & "SELECT DateAdd('m',1,[TrDate])as nextMonthDate, Description, CrValue, FixedExpense, TrStatus FROM tblFinanceTransaction;"
    
    If rs("FixedExpense") = True Then
        DoCmd.RunSQL (strSQL)
    Else
    End If
    rs.Edit
    rs("TrStatus").Value = True
    rs.Update
    rs.MoveNext
Next i
 
Upvote 0

Forum statistics

Threads
1,221,825
Messages
6,162,166
Members
451,750
Latest member
dofrancis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top