Update Query not working on last record (1 Viewer)

GinaWhipp

AWF VIP
Local time
Yesterday, 21:56
Joined
Jun 21, 2011
Messages
5,899
I just got another thought, I have rearranged some lines and added a few, let's see if this works...

Code:
Private Sub cboPoCurrency_AfterUpdate()
On Error GoTo ErrHandler
    Dim db As Database
    Dim strSql As String
        [COLOR=red][B]Dim lngID As Long '***Why is this here?
[/B][/COLOR]    Dim dblRate As Double
    Set db = CurrentDb
       [B][COLOR=red] lngID = Me.txtID '***Why is this here?
[/COLOR][/B]    dblNCostR = DLookup("ExRate", "Currency", "ID = " & [cboPoCurrency])
    dblRate = dblNCostR / dblOCostR
    DoCmd.SetWarnings False
    DoCmd.RunCommand acCmdSaveRecord
    Me.txtPOExchRate.Value = dblNCostR
    DoEvents
    strSql = "UPDATE QuoteLineItems SET QuoteLineItems.UnitCost = [UnitCost] * " & dblRate & _
                " WHERE QuoteLineItems.QuoteID = " & Me.txtID & ";"
    DoCmd.RunSQL strSql
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.SetWarnings True
        Set db = Nothing
ExitSub:
    Exit Sub
ErrHandler:
    Call ErrorAlert
    Resume ExitSub
End Sub
 

jerem

Registered User.
Local time
Today, 09:56
Joined
May 1, 2012
Messages
118
As you were saying... great minds think alike. While reviewing the code I noticed: I have declared the lngID variable and have not used it.
Basically the me.txtID in the SQL statement should be replaced by the variable lngID
 

jerem

Registered User.
Local time
Today, 09:56
Joined
May 1, 2012
Messages
118
But this has no effect on the outcome.
 

GinaWhipp

AWF VIP
Local time
Yesterday, 21:56
Joined
Jun 21, 2011
Messages
5,899
Oh, no it doesn't just cleaning up as long as I'm reading...

Did the moving around make any difference? And really, you can leave the Me.txtID, no reason to do it that way doesn't *save* anything.
 

jerem

Registered User.
Local time
Today, 09:56
Joined
May 1, 2012
Messages
118
alright... thanks for the advice. There is no difference. I can see that the save and doEvents make the whole process a bit slower but the result is the same. Last modified record doesn't get updated.
 

jerem

Registered User.
Local time
Today, 09:56
Joined
May 1, 2012
Messages
118
I just turn the problem around in my head and really I can't see. It's making me crazy!
 

GinaWhipp

AWF VIP
Local time
Yesterday, 21:56
Joined
Jun 21, 2011
Messages
5,899
Lightbulb! Let's requery the Subform, put the line below in place of DoEvents...

Code:
[SubformName].Requery
 

GinaWhipp

AWF VIP
Local time
Yesterday, 21:56
Joined
Jun 21, 2011
Messages
5,899
Making you crazy! I'm still here too! :banghead:
 

jerem

Registered User.
Local time
Today, 09:56
Joined
May 1, 2012
Messages
118
Yes thank you so much for trying!!! And it must be very late for you!
 

jerem

Registered User.
Local time
Today, 09:56
Joined
May 1, 2012
Messages
118
and unfortunately... No effect.


Code:
Private Sub cboPoCurrency_AfterUpdate()
On Error GoTo ErrHandler
    Dim db As Database
    Dim strSql As String
    Dim dblRate As Double
    Set db = CurrentDb
    dblNCostR = DLookup("ExRate", "Currency", "ID = " & [cboPoCurrency])
    dblRate = dblNCostR / dblOCostR
    DoCmd.SetWarnings False
    Application.RunCommand acCmdSaveRecord
    Me.sbfProductDetails.Form.Requery
    strSql = "UPDATE QuoteLineItems SET QuoteLineItems.UnitCost = [UnitCost] * " & dblRate & _
                " WHERE QuoteLineItems.QuoteID = " & Me.txtID & ";"
    DoCmd.RunSQL strSql
    Me.txtPOExchRate.Value = dblNCostR
    Set db = Nothing
ExitSub:
    Exit Sub
ErrHandler:
    Call ErrorAlert
    Resume ExitSub
End Sub
 

GinaWhipp

AWF VIP
Local time
Yesterday, 21:56
Joined
Jun 21, 2011
Messages
5,899
Hmm, I'm gaathering by your reply that did not work either. Did the Subform even react?

Not too late... a little after midnight. It's the shank of the evening or should I say morning... :D
 

GinaWhipp

AWF VIP
Local time
Yesterday, 21:56
Joined
Jun 21, 2011
Messages
5,899
Do you have a stripped down file you can send? I feel like I'm on a mission now...
 

jerem

Registered User.
Local time
Today, 09:56
Joined
May 1, 2012
Messages
118
Can it be sent in private? I would take a bit of time to strip it.
 

GinaWhipp

AWF VIP
Local time
Yesterday, 21:56
Joined
Jun 21, 2011
Messages
5,899
This line...
Code:
Me.sbfProductDetails.Form.Requery
should be
Code:
Me.sbfProductDetails.Requery
 

jerem

Registered User.
Local time
Today, 09:56
Joined
May 1, 2012
Messages
118
Well it's about lunch time on a very sunny day here... I'm based in Hong Kong.
 

GinaWhipp

AWF VIP
Local time
Yesterday, 21:56
Joined
Jun 21, 2011
Messages
5,899
Yes, if you go to my website under my signature there is a Contact form where you can upload, please zip and it needs to be under 5mb
 

jerem

Registered User.
Local time
Today, 09:56
Joined
May 1, 2012
Messages
118
tried
Code:
 Me.sbfProductDetails.Requery
but no luck

Is there a way to send you the strip file later? I'm sorry but I need to leave now. I can send it later in the afternoon. Thanks so much for helping with this.
 

GinaWhipp

AWF VIP
Local time
Yesterday, 21:56
Joined
Jun 21, 2011
Messages
5,899
Hmm, okay, it's almost 1:00 am and still no file. :confused: This might have to wait till *my* morning (or rather later today) because I'm getting sleepy!

EDIT (ADD): Well, I guess you went to lunch, so I'll look later today (it's 1:15 AM here). Have a great sunny day! :)
 
Last edited:

Users who are viewing this thread

Top Bottom