Compile error: Method or data member not found

S

shank

I'm getting this error...
Compile error: Method or data member not found
..Edit is highlighted when the error occurs.
Can someone decipher the error a bit and give me a clue where to look?
thanks!

Public Function RunningCount()
Dim db As Database
Dim rs As Recordset
Dim intCount As Integer
Dim strOrder As String
Set db = CurrentDb
Set rs = db.OpenRecordset("TempCompTitles", dbOpenDynaset)
With rs
.MoveFirst
Do Until .EOF
If ![OrderNo] = strOrder Then intCount = intCount + 1 Else intCount =
1
.Edit <--THIS IS HIGHLIGHTED
![SortKey] = intCount
strOrder = ![OrderNo]
.Update
.MoveNext
Loop
End With
End Function
 
G

Gary Walter

Hi shank,

First, it appears to me that you are
missing an "End If"

One good code habit that I once saw
reinforced by Tom is:

whenever you type out the first line
of an If stmt,

skip a line,

type in "Else"

skip a line,

type in "End If"

then go back and fill in the skipped lines.

This always assures you are handling
(or not) both cases of the If stmt.

Plus it is always a good idea to "disambiguate"
rs (and db) in Dim stmt(s) with "DAO." Of course,
you will need to have set reference to the DAO library.

Another good coding rule is

If you open it, close it and set to nothing.

So....you might try:

Public Function RunningCount()
On Error GoTo Err_RunningCount
Dim rs As DAO.Recordset
Dim intCount As Integer
Dim strOrder As String
Set rs = CurrentDb.OpenRecordset("TempCompTitles", dbOpenDynaset)

'you might want to check RecordCount here
'if there is ever a chance TempCompTitles
'will not return any records
'If rs.RecordCount = 0 then
' Msgbox "No records found in TempCompTitles."
' rs.Close
' Set rs = Nothing
' Exit Function
'Else
' 'continue
'End If

With rs
.MoveFirst
Do Until .EOF
If ![OrderNo] = strOrder Then
intCount = intCount + 1
Else
intCount = 1
End If
.Edit
![SortKey] = intCount
strOrder = ![OrderNo]
.Update
.MoveNext
Loop
End With

rs.Close

Exit_RunningCount:
Set rs = Nothing
Exit Function
Err_RunningCount:
MsgBox "Error: " & Err.Description & " (" & Err.Number & ")"
Resume Exit_RunningCount
End Function

(I did not take the time to check
what your code is actually doing....
hopefully this will get you going.)

Good luck,

Gary Walter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top