Question : Code not returning result unless a breakpoint is set!

Hi,
I have the following Sub:

Private Sub FreightCharge_AfterUpdate()
Dim sngVAT As Single
sngVAT = DLookup("VATrate1", "Variables")
Debug.Print "sngVAT="; sngVAT
Me.Visible = True
Me.cmdAcceptOrder.Enabled = True
If IsEmpty(Me.FreightCharge) Or IsNull(Me.FreightCharge) Then Me.FreightCharge = 0
Me.ProductsCostTotal = Me!sbfrmOrderItems.Form!SalePriceTotal
Debug.Print "Me!sbfrmOrderItems.Form!SalePriceTotall="; Me!sbfrmOrderItems.Form!SalePriceTotal
Debug.Print Me.ProductsCostTotal
Me.InvoiceNet = Me.ProductsCostTotal + Me.FreightCharge
Debug.Print Me.InvoiceNet; Me.ProductsCostTotal; Me.FreightCharge
Me.VatTotal = Me.InvoiceNet * sngVAT
Debug.Print Me.VatTotal
Me.InvoiceTotal = Me.InvoiceNet + Me.VatTotal
End Sub

This sud return 0 in everything except the 'sngVAT' if it is allowed to run normally.
However if I set a break point at or before 'Me.ProductsCostTotal = Me!sbfrmOrderItems.Form!SalePriceTotal"

It works as I expect and gives the correct resullts!

All the debug.print statements are of course to tryand  see what is going on
Any idea why this should be.

Thanks

Peter

Answer : Code not returning result unless a breakpoint is set!

Maybe it's possible that
Me!sbfrmOrderItems.Form!SalePriceTotal
has no time to be updated based on your application's processing work.

Just put a
DoEvents()
instruction before the
Me.ProductsCostTotal = Me!sbfrmOrderItems.Form!SalePriceTotal
line and I think it will work well.

Hope that helps.
Random Solutions  
 
programming4us programming4us