Maximum length of body text in SendObject?

What is wrong with this code?  It very frequently generates an Invalid Page Fault in Kernel32.dll.

If I comment out the While/Wend loop, the errors stop.

Could it be that there is a limit to the length of the TheBody string, or is there a limit to the size of the body text that can be sent via a SendObject?


Private Sub buttonCloseForm_Click()
On Error GoTo Err_Command92_Click
Dim TheBody, EmailAddress, InputData As String

 Open "c:\windows\win.ini" For Input As #1
 While Not EOF(1)
   Line Input #1, InputData
   TheBody = TheBody & InputData & vbCrLf
 Wend
 Close #1
 DoCmd.SendObject , , acFormatTXT, "bill.gates@microsoft.com", , , "WIN.INI", TheBody, 0

Exit_Command92_Click:
    DoCmd.Close
    Exit Sub

Err_Command92_Click:
    MsgBox Err.Description
    Resume Exit_Command92_Click
End Sub

Monroe406Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TrygveCommented:
As the code stands now, TheBody and EmailAddress is declared as Variant data type which might not be a generous when it comes to size as String for string values. From help "A variable-length string can contain up to approximately 2 billion (2^31) characters." That should be enough...
0
Monroe406Author Commented:
But the EmailAddress will never be more than 100 characters, nor will the TheBody contain anything more than 3 pages of ASCII text.   So I don't see where there would be a problem.
0
TrygveCommented:
This does not sound to be too large, but try using this line instead

Dim TheBody As String, EmailAddress As String, InputData As String

and let us know.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Monroe406Author Commented:
>This does not sound to be too large,
>but try using this line instead

>Dim TheBody As String, EmailAddress As
>String, InputData As String


I have done the following instead...

Dim TheBody As String
Dim EmailAddress As String
Dim InputData As String

And yet...the Invalid Page Fault in Kernel32.dll continue to occur.

Can someone please test the following code using Access 2000 and Outlook 2000?  The problem does not occur with Access 97.  I have moved the .mdb to a second PC, and it too generates the very same error.


Dim TheBody As String
Dim EmailAddress As String
Dim InputData As String
Dim Ctr As Integer

EmailAddress = "yourname@goes.here"

For Ctr = 1 to 10
 Open "c:\windows\win.ini" For Input As #1
 While Not EOF(1)
   Line Input #1, InputData
   TheBody = TheBody & InputData & vbCrLf
 Wend
 Close #1
 DoCmd.SendObject , , acFormatTXT, EmailAddress, , , "WIN.INI", TheBody, 0
Next

DoCmd.Close
 
End Sub
0
TrygveCommented:
The SendObject method does not work very well with my installation. I get "Outlook can't create the item" or something like that. So I can't help you test the code, but here is a link to an article of how to send objects (in the article charts are sent) via EMail. Perhaps you can adapt the code to your needs?

http://www.netservice.no/trygve/WIZ/FrameText.asp?ArticleID=080FE58F-49A4-11D3-A9BB-005004227874
0
TrygveCommented:
I will try to put it together, but since I don't have Outlook installed on this machine, I can't guarantee anything 100% :-)

Remember that you need to go into a code module, select Tools, References and check the line Microsoft Outlook 9.0 Object Library to make the code work.

Button on a form called cmdEmailWinIni with this code in the OnClick event.

Private Sub cmdEmailWinIni_Click()
  '=============================================
  '     Purpose: E-Mail Win.Ini
  '      E-Mail: bill.gates@microsoft.com
  '  Programmer: Graeme Wilson
  '  Adjusted by: Trygve
  '=============================================
On Error GoTo cmdEmailWinIni_Click_Err
    Dim strErrMsg As String 'For Error Handling
    Dim olApp As New Outlook.Application
    Dim olNameSpace As Outlook.NameSpace
    Dim olMail As Outlook.MailItem
    Dim strFileName As String
   
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olMail = olApp.CreateItem(olMailItem)
strFileName = "c:\windows\win.ini"
oleGrf.Export FileName:=strFileName

With olMail
    .To = "bill.gates@microsoft.com"
    .Subject = "Win.ini Copy for you" & Format(Now(), "dd mmm yyyy  hh:mm")
    .Attachments.Add strFileName
    .ReadReceiptRequested = False
    .Send
End With

MsgBox vbCrLf & "Win.Ini has been E-Mailed", _
        vbInformation + vbOKOnly, "Win.Ini Exported :"


cmdEmailWinIni_Click_Exit:
Set olApp = Nothing
Set olMail = Nothing
     Exit Sub

cmdEmailWinIni_Click_Err:
    Select Case Err
        Case Else
            strErrMsg = strErrMsg & "Error #: " & Format$(Err.Number) & vbCrLf & vbCrLf
            strErrMsg = strErrMsg & "Error Description: " & Err.Description & vbCrLf
            MsgBox strErrMsg, vbInformation, "cmdEmailWinIni_Click"
            Resume cmdEmailWinIni_Click_Exit
    End Select

End Sub
'************ Code End *************
0
Monroe406Author Commented:
Trygve,

Thank you for taking the time to assist, but your sample code has assumed too much.  I never wanted to send an attachment.  I want to read in a text file, one line at a time, so that I can perform certain operations on each line of text....then send the result (TheBody) as the contents of a new email.  Your code skips over this aspect of my original code altogether.
0
TrygveCommented:
Sorry, I missed out on that part.

You know that your code loops ten times without resetting the TheBody variable between each run?

Perhaps this can be part of the problem.

When you dim a variable as variant (like you used to) and set Variable = Variable & SomethingElse then Variable is originally NULL and the result of the expression is unpredictable...

Now, that you have declared TheBody as string it is originally "" which means that the expression will work nicely.

Try this adjusted loop and see what happens. I might not read my EMail before monday so bare with me if I don't respond to your finding before that...

For Ctr = 1 to 10
 TheBody = "" ' Reset the variable to be ready for this run of the loop
 Open "c:\windows\win.ini" For Input As #1
 While Not EOF(1)
   Line Input #1, InputData
   TheBody = TheBody & InputData & vbCrLf
 Wend
 Close #1
 DoCmd.SendObject , , acFormatTXT, EmailAddress, , , "WIN.INI", TheBody, 0
Next

0
Monroe406Author Commented:
The problem still exists.

Does anyone have Access 2000 and Outlook 2000 installed on a Windows 98 PC?
0
TrygveCommented:
I managed to test it at work after having reinstalled a couple of times...

If I run the code like you posted it originally I get the kernel error too. BUT: When I added the line that reset TheBody before each loop it sends 10 perfect copies.

The line that crashes is the Docmd.SendObject line. This indicates that the string variable does not have any problems accepting the long string, but the SendObject method chokes when the string is more than some number of characters. I will investigate a bit to figure out how many. The problems could be that Outlook does not respond as quickly as the method expects when it recieved a long string.

Do you need the string to include ten copies of the same text, or is this just some kind of test? If you have another (hidden :-)) purpose, then please let me know and we can perhaps find a workaround. If you don't want to "publish" it here, then my EMail address is in my profile.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TrygveCommented:
Reading the file ten times, then sending works. This indicates that the Docmd.SendObject command does not have problems sending large string, but it is the combination of repeated calls to the command and resetting the variable that seems to be the problem. I have analyzed a lot now, but I can't find any natular reason.

Tell me what you need from the code and we'll see.

Code that works (Resulting string is 111600 characters long)

    Dim TheBody As String
    Dim EmailAddress As String
    Dim InputData As String
    Dim Ctr As Integer
    Dim Ind As Integer
   
    EmailAddress = "yourname@goes.here"
   
    For Ctr = 1 To 10
        Open "c:\windows\win.ini" For Input As #1
            'TheBody = ""
            While Not EOF(1)
                Line Input #1, InputData
                TheBody = TheBody & InputData & vbCrLf
            Wend
        Close #1
    Next
    DoCmd.SendObject , , acFormatTXT, EmailAddress, , , "WIN.INI", TheBody, 0
0
Monroe406Author Commented:
I am pleased to know that someone can recreate the problem.  Yes, it is vary irratic...and it does not always trigger the Invalid Page Fault, and I cannot find any sure method to avoid the problem.

I will send you the actual source code that I am using, since the above code was simply an example that I whipped together for this forum.
0
TrygveCommented:
I will look at the code at the first possible moment.
0
Monroe406Author Commented:
Still waiting for a response...
0
TrygveCommented:
I have sent you a workaround on EMail. Let me know if/when you receive it.
0
TrygveCommented:
For the record: Monroe406 moved the code to outlook and it worked without crashes. How easy we forget to look for the obvious...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.