?
Solved

Microsoft's clsSendObject.SendObject doesn't work for me

Posted on 2006-07-20
12
Medium Priority
?
426 Views
Last Modified: 2008-01-09
I'm having a problem with Docmd.SendObject so I followed Microsoft's code solution (using clsSendObject) but the code doesn't work.  I get "type mismatch" error on the call:
      clsSendObject.SendObject acFormatHTML, strName, , , strSubject, strMessage, False    

So then I tried the following call and got "Object Variable or with block variable not set" error on the call:
      clsSendObject.SendObject acSendNoObject, , accOutputTXT, "schmir1", , , "xxx"

Microsoft's code is listed at:
http://support.microsoft.com/?kbid=260819



0
Comment
Question by:schmir1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
12 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17150068
so whats clsSendObject, its a variable of type accSendObject right?

Did u instanstiate it? I mean did u type in

dim clsSendObject = new accSendObject

0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 17150572
what's the problem you're having with the Docmd.SendObject command in the first place?
0
 

Author Comment

by:schmir1
ID: 17157533
Here is some more details:

I'm getting a type mismatch on intFormType in call below:

clsSendObject.SendObject intFormType, strForm, acFormatHTML, strName, , , strSubject, strMessage, False   'HTML=easier to read

I declare my mail functions as:
Sub Send_EMail(strName As String, strSubject As String, strMessage As String, strForm As String, _
               Optional intFormType As Access.AcSendObjectType = acSendNoObject, Optional Do_not_ask As Boolean)

Microsoft declares there clsSendObject.SendObject as follows:
Public Sub SendObject(Optional ObjectType As Access.AcSendObjectType = acSendNoObject, _
                      Optional ObjectName, _
                      Optional OutputFormat As accSendObjectOutputFormat, _
                      Optional EmailAddress, _
                      Optional CC, _
                      Optional BCC, _
                      Optional Subject, _
                      Optional MessageText, _
                      Optional EditMessage)

0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 65

Expert Comment

by:rockiroads
ID: 17157678
How did u define and set clsSendObject
0
 

Author Comment

by:schmir1
ID: 17157695
As follows:
  Dim clsSendObject As accSendObject
 
  Set clsSendObject = New accSendObject
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17157717
and what is

intFormType

defined as

an integer?
0
 

Author Comment

by:schmir1
ID: 17157722
Sub Send_EMail(strName As String, strSubject As String, strMessage As String, strForm As String, _
               Optional intFormType As Access.AcSendObjectType = acSendNoObject, Optional Do_not_ask As Boolean)
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17157747
I will look at this later, Ive got to go
will post comments
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17257918
Hi schmir1
Sorry about not responding earlier, I lost this bookmark and have been looking for it. Well I finally found it!


Anyways, I copied the code from MS and pasted it as a CLASS (not module) and saved it as accSendObject

I then took this line

clsSendObject.SendObject acSendNoObject, , accOutputTXT, "schmir1", , , "xxx"

And tried to work that, this is what I did

    Dim clsSendObject As accSendObject
   
   
    Set clsSendObject = New accSendObject
    clsSendObject.SendObject acSendNoObject, , accOutputTXT, "some@email.com", , , "xxx"
    Set clsSendObject = Nothing


And I had no problems whatsoever



With your other line

 clsSendObject.SendObject acFormatHTML, strName, , , strSubject, strMessage, False

You have got this wrong

the first parameter is send type i.e. acSendNoObject, acSendReport etc, not acFormatHTML
the second parameter is name of object (or nothing if no object)
the third parameter is the output type

now only 4 types are supported

accOutputRTF
accOutputSNP
accOutputTXT
accOutputXLS

there is no html output type (see my post after this on using html types)

The final line that worked for me was this

clsSendObject.SendObject acSendNoObject, , accOutputHTML, "some@mail.com", , , strSubject, strMessage, True


0
 
LVL 65

Accepted Solution

by:
rockiroads earned 2000 total points
ID: 17257919
MODIFYING CODE TO HANDLE HTML

I think the reason why its not supported is perhaps it can't be done properly? I dont know. Have a look at this

If u want to cater for html format, u have to modify the class accSendObject

this is what u can try

Look for the enum accSendObjectOutputFormat and modify
e.g.
Public Enum accSendObjectOutputFormat
    accOutputRTF = 1
    accOutputTXT = 2
    accOutputSNP = 3
    accOutputXLS = 4
    accOutputHTML = 5
End Enum

Next, look for the function called GetExtension and modify
e.g.

Private Function GetExtension(ObjectType As Long) As String
    Select Case ObjectType
        Case 1 'RTF
            GetExtension = ".RTF"
        Case 2 'TXT
            GetExtension = ".TXT"
        Case 3 'SNP
            GetExtension = ".SNP"
        Case 4 'XLS
            GetExtension = ".XLS"
        Case 5 'HTM
            GetExtension = ".HTML"
    End Select
End Function

And now modify the function below that, GetOutputFormat
e.g.
Private Function GetOutputFormat(ObjectType As Long)
    Select Case ObjectType
        Case 1 'RTF
            GetOutputFormat = Access.acFormatRTF
        Case 2 'TXT
            GetOutputFormat = Access.acFormatTXT
        Case 3 'SNP
            GetOutputFormat = Access.acFormatSNP
        Case 4 'XLS
            GetOutputFormat = Access.acFormatXLS
        Case 5 'HTM
            GetOutputFormat = Access.acFormatHTML
    End Select
End Function


0
 

Author Comment

by:schmir1
ID: 17272872
Thanks.  It works great.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17273202
I would of done it sooner had I not lost the bookmark!
There are 2 other questions I need to finish also, but I cant for the life of me find them!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question