Error message (1 Viewer)

skwilliams

Registered User.
Local time
Today, 11:44
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, 15:44
Joined
Dec 10, 2002
Messages
11,316
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
Today, 11:44
Joined
Jan 18, 2002
Messages
516
Works perfectly.

Thanks.
 

Users who are viewing this thread

Top Bottom