Cause of 'object can't support this method' error using find method? (1 Viewer)

Margarita

Registered User.
Local time
Today, 11:01
Joined
Aug 12, 2011
Messages
185
Hello, I apologize if this is a repeat of one of the many threads there are on the error 'object can't support this property or method'- but nothing that I found seems to pertain to my problem and I am really becoming frustrated.
I am taking some data from access queries and pasting them in an excel workbook, wb. Then, in each sheet, at the bottom of the pasted data, I am inserting a comments/footnotes section. These comments are pasted from a recordset called rs_subtaskcomments. The recordset contains the fields Name and CommentsSet.
Each comment is preceded by a comments counter. Each row (name) corresponds to each value of comments counter and is pasted as
commentcounter & " " & rs_subtaskcomments.fields("CommentsSet").value line by line.
After each line is pasted, the code needs to do the following: find the name that corresponds to the field 'Name' in the current record, and insert the commentcounter value as a superscript at the end of that string (all names to be serached are contained in column A).
I am trying to accompish this find and insert step using the find method, but I am having A LOT of trouble and, quite frankly, am on the verge of insanity. The workbook exists, the sheet exists, the range exists, the reference to the method is valid. I have no clue why this thing keeps spitting out an error at me. PLEASE help! I would greatly appreciate any advice you could give me! Here is the 'insert comments' section of the code- the debugger highlights the entire line that countains the find method:

PHP:
If Not (rs_subtaskcomments.EOF = True And rs_subtaskcomments.BOF = True) Then              '-----start of if comments rs non empty loop
rs_subtaskcomments.MoveFirst
 
'initialize the comments counter that keeps track of superscript- one superscript per name,
 
CommentCounter = 1
Dim foundnamecell As Variant
Dim orignamestring As String
Dim lenorigstring As Long
Dim commentstring_multline As String
 
 
'LOOP through Comments rs
 
Do While Not rs_subtaskcomments.EOF
'replace the space between different comment types with a new line
commentstring_multline = Replace(rs_subtaskcomments.Fields("CommentsSet"), ". ", vbNewLine)
 
'paste comments string below temps section
wb.sheets(currentsubtasktemplate).range("A" & lastrowtemps + 1).Value = _
CommentCounter & " " & commentstring_multline
wb.sheets(currentsubtasktemplate).range("A" & lastrowtemps + 1).Characters(Start:=1, Length:=0).Font.Superscript = True
wb.sheets(currentsubtasktemplate).range("A" & lastrowtemps + 1).Characters(Start:=2, Length:=0).Font.Superscript = False
'find the first place where employee name appears and paste superscript
'Set foundnamecell =
Dim namevalue As String
namevalue = rs_subtaskcomments.Fields("Name").Value
Debug.Print namevalue
 
foundnamecell = wb.sheets(currentsubtasktemplate).range("A1:A200").Find(What:=namevalue, After:=wb.range("A200"), LookIn:=xlValues, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
 
orignamestring = foundnamecell.Value
lenorigstring = Len(orignamestring)
foundnamecell.Value = orignamestring & CommentCounter
'convert inserted commentcounter to superscript
foundnamecell.Characters(Start:=lenorigstring + 1, Length:=0).Font.Superscript = True
'go to next commentcounter
CommentCounter = CommentCounter + 1
Loop
End If   '-----end of comments loop

(working in access 2003)
 
Last edited:

SforSoftware

(NL) SnelStart specialist
Local time
Today, 17:01
Joined
Aug 16, 2003
Messages
239
In the After-parameter you use 'wb.range', shouldn't that be 'wb.sheets(...).range' ?
 

Margarita

Registered User.
Local time
Today, 11:01
Joined
Aug 12, 2011
Messages
185
Thank you, Bert! That was silly mistake on my part, which I just couldn't see because I guess I looked at it too much and it was hard for me to step back and really look at the line part by part. I ended up going with a loop in that particular section, but I think it's worthwhile to go back and get the find method to work- it's probably going to be faster.
Thanks!
 

Users who are viewing this thread

Top Bottom