query to textbox

B

Brennan

I have the following group of code, but I keep getting a "no current record"
error. I realize that there will be instances when there is not a record
that comes up via the SQL, but I need it to just populate a zero (0) value in
that field when it happens. Doesn't the if isnull statement handle that
type of error. If some kind person can check my code and let me know how to
fix it, I would appreciate the help. Thanks all.

Private Sub presaleupdate()
Dim str As String
Dim rs As DAO.Recordset
Dim combo1 As String
Dim db As DAO.Database

combo1 = Me.AccountingPeriod

str = "SELECT Sum([Lent - Postsale].Lentcredit) AS SumOfLentcredit FROM
[Lent - Postsale]GROUP BY [Lent - Postsale].[Cost Summary Period] HAVING
((([Lent - Postsale].[Cost Summary Period])='" & combo1 & "'));"
Set db = CurrentDb
Set rs = db.OpenRecordset(str, dbOpenSnapshot)




If IsNull(rs!SumOfLentcredit.Value) Then
Me.postsalelent1 = "0"
Else
With rs!SumOfLentcredit
Me.postsalelent1 = rs!SumOfLentcredit.Value
End With


End If

rs.Close
db.Close

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description & Err.Number
Resume Exit_Handler

End Sub
 
D

Danny Seager

no. as ther are no records to check the null against.

try adding

rs.movelast
rs.movefirst

if rs.recordcount>0 then
Me.postsalelent1 = rs!SumOfLentcredit.Value
else
Me.postsalelent1 = 0
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top