'Emailing routine on Access form: Runtime Error 3265

I'm putting together an emailing routine on an Access form.

I get a 3265 Error.

This is the bit that causes the error.

SendToEmail = HyperlinkPart(rs![Client Basics].email, acDisplayedValue)
Cref = rs![Client Basics].[Client Ref]
Cdear = rs![Client Basics].Dear

This is the bit of code that is causing the problem.

Dim strSQL As String
strSQL = "SELECT DISTINCTROW Events.[Client Ref], Events.Date, Events.[Event Type], Events.[Event Details], Events.[Advance Code], Events.[Advance Date], Events.Operator, [Client Basics].[Client Ref], [Client Basics].[Client Name],[Client Basics].email, [Client Basics].Dear FROM [Client Basics] INNER JOIN Events ON [Client Basics].[Client Ref] = Events.[Client Ref] WHERE (((Events.[Advance Code])=88) AND ((Events.[Advance Date])<Date()));"
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset(strSQL)


'----------------------------------------------------------Start Email Loop for all Clients Selected -----------------------------------
If Not rs.BOF And Not rs.EOF Then
    rs.MoveFirst
    Do While Not rs.EOF    
        SendToEmail = HyperlinkPart(rs![Client Basics].email, acDisplayedValue)
        Cref = rs![Client Basics].[Client Ref]
        Cdear = rs![Client Basics].Dear
        
        FinalHTML = "<p style=""text-align: right;""><img src=""https://www.accountants.co.uk/logo2.png"" alt="""" /></p><p>Dear " + Cdear + "</p><p>Ref " + Cref + "</p>" + HTMLFile

        Set myMail = myOutlApp.CreateItem(olMailItem)
        With myMail
            .To = SendToEmail
            .subject = DigSubject
            .BodyFormat = olFormatHTML
            .HTMLBody = FinalHTML
            .Display
        End With
        rs.MoveNext
            
    Loop
End If
    
rs.Close
Set rs = Nothing
Set myMail = Nothing
Set myOutlApp = Nothing


Solution 1:[1]

I have finally fixed it. I had to add a bit to the SQL Where I had :-

[Client Basics].[Client Ref], ......

I changed it to

[Client Basics].[Client Ref] AS FromRef, .....

Then used

Cref = rs!FromRef

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bwian