DBServices
Programmer
I have been building a database for my barber shop. On my unbound "frmHaircuts" I have some option buttons for the user to select which kind of haircut the customer just received. I have corresponding text boxes with DLookups as the control source displaying the price for the selected haircut. Once they select the haircut, then in the payment selection there are some option buttons to select which kind of payment such as cash, credit, etc...Once all the mandatory fields are populated, there is a "cmdSubmit" which runs an Append Query and inserts the record into the "tblHaircuts". At the end of the day, I want to run a "End of Day Totals" query which will sum up the total money received in the "tblHaircuts" and insert a record into the "tblLedger" to show the daily sales for financial info. The "qryDailySales" is only pulling back three fields (the current date grouped, total sales, and the income type which is "6" because that is the ID for haircuts in my "tblIncomeType". All is well up to this point, however, an issue came up. Let's say they run the end of day function and then have to cut another haircut. Then they will have to run the end of day function again so what I want to do is pull back a recordset from the "tblLedger" and loop through it to find the record that has been inserted and update the total with the new value. Below is the code I have so far but I'm at a roadblock, as you can see, I've had to comment out what I want to do because I don't know how to structure my VBA correctly and need some help. Thank you...Dannie.
Code:
Private Sub cmdEndOfDay_Click()
'Dim strSQL As String, dbs As DAO.Database, rsSQL As DAO.Recordset , salesDate As Date
' Set dbs = CurrentDb
' salesDate = Date
' Set rsSQL = dbs.OpenRecordset(strSQL2, dbOpenSnapshot)
'
'
' rsSQL.MoveFirst
'
' If rsSQL.Fields(1).Value = Date And rsSQL.Fields(4).Value = True Then
' If MsgBox("You have already submitted the End of Day totals, run again?", vbYesNo) = vbYes Then
' run update query to update the DebitIn to reflect the new value
' (The first IF statement is looking to see if there's a value in the DebitIn field of my ledger table along with
' current date which will be the record I'm looking for....)
Dim strSQL As String
strSQL = "INSERT INTO tblLedger (LedgerDate, DebitIn, IncomeType)SELECT HaircutDate, SumOfTotalPrice, IncomeType FROM qryDailySales"
If MsgBox("Are you ready to run the end of day totals?", vbYesNo, "END OF DAY") = vbYes Then
DoCmd.SetWarnings (False)
DoCmd.RunSQL strSQL
DoCmd.SetWarnings (True)
Else
MsgBox ("...")
Me.Undo
Me.FrameHaircutStyles.SetFocus
End If
End Sub