DAO - Error 424: Object Required

Blackelise

aka Andrew
Local time
Today, 17:52
Joined
Jun 13, 2012
Messages
35
I am trying to implement recordsets but keep getting this error at run time and I can't see why!

The code is:
PHP:
Dim rs As DAO.Recordset
Dim strSearchName As String
Set rs = CurrentDb.OpenRecordset("tblCustAddress")
strSearchName = Str(Me.EstOrd_CustName)
    If rs.RecordCount <> 0 Then
        rst.FindFirst "InvTo_ID = " & strSearchName  '<--it fails here!
    End If

On execusion strSearchName does contain the correct reference to be found eg "24"
Both InvTo_ID and EstOrd_CustName are set to Long Integer in the tables

I have also tried this:
PHP:
rst.FindFirst "InvTo_ID = " & Me.EstOrd_CustName
but get the same error.

any ideas gratfully recieved, thanks.
 
Perhaps:
Dim strSearchName As String
should be:
Dim strSearchName As Integer
 
You declare an object called rs. In the line that fails, you try to use an object called rst.

This problem can be solved if you Require Variable Declaration. Open a code window and go to Menu->Tools->Options->Editor Tab->Code Settings Box and check "Require Variable Declaration." This places "Option Explicit" at the top of every module, and raises a "Variable net defined" compile error for any variable you do not declare.
 
@lagbolt - thanks made the changes you suggest.

I have correct the typo - rst. for rs. - however I now get "3251 operation is not supported for this type of object"
 
Got it!!!!

The problem was quite simply that one needs to have dbOpenDynaset defined in OpenRecordSet. I don't know why as it's not shown in any examples I've seen...anyway solved my problem.

PHP:
    Dim rs As DAO.Recordset
    Dim db As DAO.Database
    Dim CustPayTerms, strSearchName As String
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tblCustAddress", dbOpenDynaset)  ' <--here
    strSearchName = Str(Me.EstOrd_CustName)
    If rs.RecordCount <> 0 Then
         rs.FindFirst "InvTo_ID = " & strSearchName
    End If

Leave it out and error 3251 appears put it back and it works a dream!

Thanks for all your help.
 

Users who are viewing this thread

Back
Top Bottom