Object required error...pls help
I get an object required error when working with rstSubjectList from cmdAdd_Click. When I go to tracking mode from the command button, it says rstSubjectList = Nothing. It seems that the recordset is not being carried accross from the form_load, despite the two events being local to each other (they are in the same form). Please tell me how I can fix this error.
VB Code:
Private Sub Form_Load()
Dim rstSubjectList As Recordset
Set rstSubjectList = db.OpenRecordset("SELECT Subject FROM Subjects ORDER BY Subject")
rstSubjectList.MoveFirst
Do While Not rstSubjectList.EOF
cboSubject.AddItem (rstSubjectList.Fields("Subject").Value)
rstSubjectList.MoveNext
Loop
End Sub
Private Sub cmdAdd_Click()
With rstSubjectList 'Add subject if it doesn't already exist
.FindFirst "Subject ='" & cboSubject.Text & "'"
If .NoMatch = True Then
.AddNew
.Fields("Subject").Value = cboSubject.Text
.Update
End If
End With
Re: Object required error...pls help
If you need your recordset object to be available throughout your application or at least form's life cycle then move declaration to general section:
Option Explicit
Dim rstSubjectList As Recordset
Although, change it to the following:
Dim rstSubjectList As New Recordset
so it would be initialized or do it during Form_Load event:
Set rstSubjectList = New Recordset
Re: Object required error...pls help
RhinoBull is correct, but I would stay away from:
VB Code:
Dim rstSubjectList As New Recordset
http://www.vbforums.com/showthread.p...ghlight=arm%2A