Question

Private Sub Form_Open(Cancel as Integer)
Dim rsnb As ADODB.Recordset
Set rsnb = New ADODB.Recordset
rsnb.Open "SELECT * FROM QmessagesNoBill WHERE messageID='" & Me.OpenArgs & "'", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Set Me.Recordset = rsnb 'set the forms recordset (me!) as the ADO recordset noted in SQL query above, see kb281998
rsnb.Close: Set rsnb = Nothing
End Sub

Hitting debug on the error it highlights the first line of text in a button event:

Private Sub btnapprove_Click()
Me.Recordset!reviewed = 1 'mark that its been reviewed
Me.Recordset.Update
End Sub

Please note:

  • This code works if I put the Dim statement outside of a event procedure
    • I only wanted to put it inside of the forms open event as it makes code look cleaner & I can put close statement there instead of in the forms close event
  • I am new to programming & am not familiar with DAO
Was it helpful?

Solution

I don't think you're supposed to close the recordset right after binding it to your form.

Try removing rsnb.Close from your code and see if that fixes it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top