Solved INSERT INTO/VBA

PatAccess

Registered User.
Local time
Today, 00:41
Joined
May 24, 2017
Messages
284
Hello Guys,
I have a form with a textbox [txtGrandTotal], which accurately sums a totalPrice every time the form is saved. I am trying to insert that value into a table every time it is updated with the date. I have tried the code on the "After Update" and "Change" events of the textbox but nothing is inserting. Can you please tell me what I am doing wrong? Here is the code
Code:
Private Sub txtGrandTotal_Change()
Dim strSQL As String

strSQL = "INSERT INTO TblGrandTotals(ChangeDate,GrandTotal)VALUES(#" & Date & "#," & Me.txtGrandTotal.Value & " )"
DoCmd.RunSQL strSQL

End Sub
 
I'm guessing that's a calculated control? Its update event wouldn't fire if so, you'd want to use the after update event of the control(s) that affect this one.
 
I'm guessing that's a calculated control? Its update event wouldn't fire if so, you'd want to use the after update event of the control(s) that affect this one.
Yes it is a calculated control. I just placed the code into the After Update of the [TotalPrice] but still nothing?
 
Is a user typing something into TotalPrice? The update events only fire when the user interacts with the control. Can you attach the db here?
 
Don't know your overall situation, but you might consider the after update event of the form instead of a control.
 
Don't know your overall situation, but you might consider the after update event of the form instead of a control.
It actually works with form AfterUpdate but it now giving me a syntax error. I don't see the error. when I step through it it shows me the correct value so could it be my ""? Change date is Date/Time and GrandToTal is currency?
Code:
Private Sub Form_AfterUpdate()
    Dim strSQL As String

    strSQL = "INSERT INTO TblGrandTotals(ChangeDate,GrandTotal)VALUES(#" & Date & "#," & Me.txtGrandTotal & " )"
    DoCmd.RunSQL strSQL
End Sub
 

Users who are viewing this thread

Back
Top Bottom