Error message (1 Viewer)

skwilliams

Registered User.
Local time
Yesterday, 21:50
Joined
Jan 18, 2002
Messages
516
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
 

Mile-O

Back once again...
Local time
Today, 02:50
Joined
Dec 10, 2002
Messages
11,312
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
 

skwilliams

Registered User.
Local time
Yesterday, 21:50
Joined
Jan 18, 2002
Messages
516
Works perfectly.

Thanks.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom