What is wrong with this code

MarkA70

Registered User.
Local time
Yesterday, 19:44
Joined
Jan 30, 2016
Messages
43
Solved: What is wrong with this code

This Code:

Dim db As DAO.Database
Dim rstAttendance As Recordset
Set rstAttendance = CurrentDb.OpenRecordset(Name:="Attendance", Type:=RecordsetTypeEnum.dbOpenDynaset)

With rstAttendance
.FindFirst [Member_ID] = Me.Member_ID
.Edit
![Dues_Paid_Family] = Me.Dues_Family_Years_Paid * Forms!frm_hidden.txt4_Hidden
![Dues_Paid_Single] = Me.Dues_Single_Years_Paid * Forms!frm_hidden.txt5_Hidden
.Update
End With

rstAttendance.Close
Set rstAttendance = Nothing
db.Close
Set db = Nothing


Generates the Error
Run-Time Error 91
Object variable or With Block Variable not set, pointer set on the db.Close statement.

What is up with that????
 
Last edited:
The variable db is declared but never assigned a value, so when you try to run its .Close method, it chokes.
 
Also, that code is vulnerable if the the call to .FindFirst fails. You should check the value of .NoMatch before proceeding with your .Edit . . .
Code:
With rst
   .FindFirst "ID = " & Me.ID
   If Not .NoMatch Then
      .Edit
      !Field1 = Me.NewData
      .Update
   End If
   .Close
End With
See what's going on there?
 
MarkK---You da man! Damn, how dumb, sometimes I just go to fast to see what I am missing. That is the exact reason for the error. THANKS Again!

(Most Marks are GOOD GUYS!)
 

Users who are viewing this thread

Back
Top Bottom