What is wrong with this code (1 Viewer)

MarkA70

Registered User.
Local time
Today, 13:53
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:

MarkK

bit cruncher
Local time
Today, 11:53
Joined
Mar 17, 2004
Messages
8,181
The variable db is declared but never assigned a value, so when you try to run its .Close method, it chokes.
 

MarkK

bit cruncher
Local time
Today, 11:53
Joined
Mar 17, 2004
Messages
8,181
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?
 

MarkA70

Registered User.
Local time
Today, 13:53
Joined
Jan 30, 2016
Messages
43
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

Top Bottom