Solved INSERT INTO/VBA (1 Viewer)

PatAccess

Registered User.
Local time
Today, 08:57
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
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:57
Joined
Aug 30, 2003
Messages
36,124
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.
 

PatAccess

Registered User.
Local time
Today, 08:57
Joined
May 24, 2017
Messages
284
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?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:57
Joined
Aug 30, 2003
Messages
36,124
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?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:57
Joined
Aug 30, 2003
Messages
36,124
Don't know your overall situation, but you might consider the after update event of the form instead of a control.
 

PatAccess

Registered User.
Local time
Today, 08:57
Joined
May 24, 2017
Messages
284
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

Top Bottom