Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 26th, 2008, 12:10 AM
Registered User
 
Join Date: May 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access 2000 insert xls into email

Hi All, I am fairly new to VBA. I have recently been working on a Database program and at one point, I execute a private sub to send a snapshot of a report. I also want to include a full .xls into the email. I can't seem to figure this one out.

I have the Beginning Access 2000 by Wrox, Chapter 9 shows how to include the snapshot in the email but not how to also include any other files.

I can set the edit message to true and insert it myself, but I would like some automagic fix.

Any help would be greatly appreciated
 
Old May 27th, 2008, 12:50 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

What is the means of sending an email with a snapshot in it? (Not having this book, it would help to know what it is that you are doing.)
 
Old May 29th, 2008, 07:46 PM
Registered User
 
Join Date: May 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To answer the question: I am writting an application that prints a Ticket for an Offence under the OHSA. The Application will also print a Summons under the OHSA. The Courts and our Crown Prosecutor need to receive a snapshot of the ticket only but need a snapshot of the Summons and an .xls document sent as well.

[This is the SUB Code for a Ticket….ALL OK]

'This is where the EMAIL Happens
Dim SSU As String 'For SUBJECT LINE
SSU = (MB20) & ", " & (MB21) ' SSU is the Subject Line for the email
Dim SLSBA1 As Variant 'For SEND TO LINE
Dim SLSBA2 As Variant 'For CC LINE
Dim SLSBA3 As Variant 'Program Assistants Email Address
DoCmd.OpenTable ("tblINSID"), acViewNormal, acEdit
Dim recSTO As Recordset
Set db = CurrentDb()
Set recSTO = db.OpenRecordset("tblINSID")
recSTO.MoveFirst
SLSBA1 = recSTO.Fields("OutMail1") 'SLSBA1 is the SEND TO LINE for Email
SLSBA2 = recSTO.Fields("IDEmail") 'SLSBA2 is the CC LINE for Email
SLSBA3 = recSTO.Fields("OutMail3") 'SLSBA3 is the PA's Address for Email
DoCmd.RunMacro ("F35Mac")
Dim TTS1 As String 'Messge to appear in Body of email for Ticket sent to LSB
TTS1 = "This email was Auto-Generated by the PITP Version 3.0 Ticket Program"
'DoCmd.SendObject acSendReport, "LSBTicket", acFormatSNP, SLSBA1, SLSBA2, SLSBA3, SSU, TTS1, False
'SNP copy of the current ticket was sent.

[This is the SUB Code for A Summons…..Need Snapshot and .xls]

'This is where the EMAIL Happens
Dim SSU As String 'For SUBJECT LINE
SSU = (MB20) & ", " & (MB21) ' SSU is the Subject Line for the email
Dim SLSBA1 As Variant 'For SEND TO LINE
Dim SLSBA2 As Variant 'For CC LINE
Dim SLSBA3 As Variant 'Program Assistants Email Address
DoCmd.OpenTable ("tblINSID"), acViewNormal, acEdit
Dim recSTO As Recordset
Set db = CurrentDb()
Set recSTO = db.OpenRecordset("tblINSID")
recSTO.MoveFirst
SLSBA1 = recSTO.Fields("OutMail2") 'SLSBA1 is the SEND TO LINE for Email(Summons)
SLSBA2 = recSTO.Fields("IDEmail") 'SLSBA2 is the CC LINE for Email (Inspector)
SLSBA3 = recSTO.Fields("OutMail3") 'SLSBA3 is the PA's Address for Email
DoCmd.RunMacro ("F35Mac")
Dim TTS1 As String 'Message to appear in Body of email for Summons sent to LSB
Dim INTX As String 'addition Message
TTS1 = "This email was Auto-Generated by the PITP Version 3.0 Ticket/Summons Program. "
INTX = "Included in this email is a snapshot of the Summons and an Auto-Populated PNR"
DoCmd.SendObject acSendReport, "rptPNRCopy", acFormatSNP, SLSBA1, SLSBA2, SLSBA3, SSU, TTS1 & INTX, True
'Location is C:\MOLApps\PITP\Version3.0
'PNR is PITP-PNR.xls
'Copy of Summons is PITP-Summons.snp
MsgBox ("Insert File....C:\MOLApps\PITP\Version3.0\PITP-PNR.xls")
'Email of Summons Completed

The end of the DoCmd for the ticket is False, this will send the email Automatically. The ending is set to True for the Summons SUB so the user can manually insert the .xls

I am hopin to have a way to insert the .xls automatically and I can change the True to False. We will have several users if the application works and not all users are comfortable with computers, the easier I make it the better.

This application was created by myself with very limited knowledge of Access or VBA (I had to buy the book to have a clue). I hope that I can get this part of the application working, the rest works perfect.

Hope this information helps....
 
Old May 30th, 2008, 11:07 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

You really should make strings type String, rather than Variant. It will guard your code from some kinds of errors that otherwise are hard to find, makes your code more self-documenting, and strings in places where strings belong run faster than Variants in places where strings belong.

Also, code is a lot easier to read if you gather declarations together, and separate logical blocks with a blank line. So
Code:
    Dim SSU    As String  ' For SUBJECT LINE
    Dim SLSBA1 As Variant ' For SEND TO LINE
    Dim SLSBA2 As Variant ' For CC LINE
    Dim SLSBA3 As Variant ' Program Assistants Email Address
    Dim TTS1   As String  ' Message to appear in Body of email for Summons sent to LSB
    Dim INTX   As String  ' addition Message
    Dim recSTO As Recordset

    Set db = CurrentDb()

    SSU = (MB20) & ", " & (MB21) ' SSU is the Subj. Line for the email
    DoCmd.OpenTable ("tblINSID"), acViewNormal, acEdit

    Set recSTO = db.OpenRecordset("tblINSID")

    recSTO.MoveFirst                   ' Recordsets always open to the 1st record...  _
                                         Drop this “.MoveFirst” habit.
    ' This is a simpler way to do this.
    ' But since you only use these variables once, it is even
    ' easier to just use the recordset in the DoCmd
    ' statement...  See 2nd listing...
    With recSTO
        SLSBA1 = !OutMail2             ' SLSBA1 is the SEND TO LINE for Email(Summons)
        SLSBA2 = !IDEmail              ' SLSBA2 is the CC LINE for Email (Inspector)
        SLSBA3 = !OutMail3             ' SLSBA3 is the PA's Address for Email
    End With

    DoCmd.RunMacro ("F35Mac")

    TTS1 = "This email was Auto-Generated by the PITP Version 3.0 Ticket/Summons Program.  "
    INTX = "Included in this email is a snapshot of the Summons and an Auto-Populated PNR"

    DoCmd.SendObject acSendReport, "rptPNRCopy", acFormatSNP, _
                     SLSBA1, SLSBA2, SLSBA3, SSU, TTS1 & INTX, _
                     True

    ' Location is C:\MOLApps\PITP\Version3.0
    ' PNR is PITP-PNR.xls
    ' Copy of Summons is PITP-Summons.snp
    MsgBox "Insert File....C:\MOLApps\PITP\Version3.0\PITP-PNR.xls" ' Parens indicate that there
                                                                    ' will be a return value...
    ' Email of Summons Completed

[u]2nd listing</u>

    Dim SSU    As String  ' For SUBJECT LINE
    Dim TTS1   As String  ' Message to appear in Body of email for Summons sent to LSB
    Dim INTX   As String  ' addition Message
    Dim recSTO As Recordset

    Set db = CurrentDb()

    DoCmd.OpenTable ("tblINSID"), acViewNormal, acEdit

    DoCmd.RunMacro ("F35Mac")

    TTS1 = "This email was Auto-Generated by the PITP Version 3.0 Ticket/Summons Program.  "
    INTX = "Included in this email is a snapshot of the Summons and an Auto-Populated PNR"
    SSU = (MB20) & ", " & (MB21) ' SSU is the Subj. Line for the email

    Set recSTO = db.OpenRecordset("tblINSID")
    With recSTO
        DoCmd.SendObject acSendReport, "rptPNRCopy", acFormatSNP, _
                         !OutMail2, !IDEmail, !OutMail3, _
                         SSU, TTS1 & INTX, _
                         True
    End With

    ' Location is C:\MOLApps\PITP\Version3.0
    ' PNR is PITP-PNR.xls
    ' Copy of Summons is PITP-Summons.snp
    MsgBox "Insert File....C:\MOLApps\PITP\Version3.0\PITP-PNR.xls" 

    ' Email of Summons Completed
    Check out this link for a more robust way to send email that will give you the functionality that you need.

http://www.mvps.org/access/modules/mdl0019.htm

Looking into this (just a little bit, so this is not definitive) leads me to think that DoCmd won’t be able to do what you want.
 
Old June 2nd, 2008, 07:02 AM
Registered User
 
Join Date: May 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Brian, I really appreciate your effort and help in this matter.
I tried the Access Module but cannot get it to work as "User Defined" errors come up. I have set the CDO in the Reference but still no luck. However I did play with the GetObject Function

Set PNR = GetObject ("C:\MOLApps\PITP\Version3.0\PITP-PNR.xls")

In the Local Window this appears to be OK.

However When I try to send via email I get an error stating that the type of file is invalid.

DoCmd.SendObject acSendObject, PNR, Excel.Application, SLSBA1, SLSBA2, SLSBA3, SSU, TTS1 & INTX, True

I also cannot see the the spreadsheet when I try:
PNR.Visible=True
All I see is a blank xls, no sheets.

I feel I am getting closer to the solution of inserting this xls as I can see the structure in the local window and if I can figure out the type of file error.

I guess I will have to concentrate on getting the Outlook Module that you linked me figured out, this seems like a much better way of sending email.

Thanks again for all your help to this point.
 
Old June 2nd, 2008, 07:49 AM
Authorized User
 
Join Date: Oct 2007
Posts: 46
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to debbiecoates
Default

Is this of any use to you? I found it on the help thingy from microsoft.

http://support.microsoft.com/kb/260819






Similar Threads
Thread Thread Starter Forum Replies Last Post
Export query param from Access form 2 XLS template gfranco Access VBA 0 April 14th, 2008 03:19 PM
how to insert image in sql 2000 mangala SQL Server 2000 18 December 17th, 2007 06:11 AM
Help about insert row in SQL Server 2000 dimeanel Beginning VB 6 3 January 19th, 2006 02:55 PM
SQL SERVER 2000 AND ACCESS 2000 ckentebe SQL Server 2000 3 June 17th, 2004 08:50 PM
Exporting access database to Excel .xls Squall Leonhart Classic ASP Databases 5 December 2nd, 2003 07:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.