Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 02-27-2003, 06:28 AM   #1
skwilliams
Newly Registered User
 
Join Date: Jan 2002
Location: Indiana
Posts: 516
Thanks: 3
Thanked 0 Times in 0 Posts
skwilliams
Error message

I'm using the following code within a tabular form. But when I move out of the first ARTot field, I receive an error because there is no previous TotUC value.

How can I correct this problem?

Private Sub ARTot_LostFocus()

Dim rst As DAO.Recordset
Dim dblValue As Double

Set rst = Me.RecordsetClone

With rst
.Bookmark = Me.Bookmark
.MovePrevious
dblValue = rst.Fields("TotUC")
End With

Me.TotUC = dblValue - Me.UC - Me.DM + Me.CashRec + Me.CM + Me.ARTot

rst.Close

End Sub

skwilliams is offline   Reply With Quote
Old 02-27-2003, 06:44 AM   #2
Mile-O
Back once again...
 
Mile-O's Avatar
 
Join Date: Dec 2002
Location: Glasgow, UK
Posts: 11,312
Thanks: 4
Thanked 118 Times in 108 Posts
Mile-O will become famous soon enough
Re: Error message

Try this:

Code:
Private Sub ARTot_LostFocus()
    
    Dim rst As DAO.Recordset
    Dim dblValue As Double
    
    Set rst = Me.RecordsetClone
    
    With rst
        .Bookmark = Me.Bookmark
        .MovePrevious
        If Not (rst.BOF) Then
            dblValue = rst.Fields("TotUC")
            Me.TotUC = dblValue - Me.UC - Me.DM + Me.CashRec + Me.CM + Me.ARTot
        Else
            Me.TotUC = Me.UC - Me.DM + Me.CashRec + Me.CM + Me.ARTot
        End If
    End With
    
    rst.Close
    
End Sub
Mile-O is offline   Reply With Quote
Old 02-27-2003, 07:01 AM   #3
skwilliams
Newly Registered User
 
Join Date: Jan 2002
Location: Indiana
Posts: 516
Thanks: 3
Thanked 0 Times in 0 Posts
skwilliams
Works perfectly.

Thanks.

skwilliams is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump




All times are GMT -8. The time now is 01:29 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World