Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2006

    Unanswered: email a form through outlook express

    hello... i'm new here... i just wanted to ask if is it possible to send a form from access through outlook express or maybe... in vb... using MAPI.. i will send an email containing a form or a table from access...?!

    hope i will get a reply as soon as possible... thanks.... ^^

  2. #2
    Join Date
    Nov 2003
    First off....Welcome to dbforums.

    If you simply want to E-Mail the data in a Form or an image of it then use the SendObject method in MS-Access. Help shows you how. Here is a sample:
    DoCmd.SendObject acSendForm, "Employees", acFormatHTML, _
        "Nancy Davolio; Andrew Fuller", "Joan Weber", , _
        "Here's a Form for ya'all.", , False
    But, if you want to send the actual developed Form itself or any other Access component (for developmental purposes) then the only way you can do this (that I know of) is to ship (E-Mail) the specific MS-Access database component(s) within a mdb file. This then means that you need to first create a blank mdb file (via code) and then Export the database component into that mdb file (again via code). Once this is done the mdb file can be attached to an E-Mail and sent (yes...again via code).

    Here is how you can go about it.........

    First, we need to create a blank MS-Access MDB file. Here is a function you can use to do this. It will create a blank MS-Access mdb file about 64K in size. Place the code into a Database Code Module:
    Public Function CreateBlankDatabase(DBName As String) As Boolean
       ' This Function has been Tested using MS-Access 2000.
       ' --------------------------------------------------------------------------
       ' ===========
       ' Creates a blank MS-Access .mdb Database.
       ' The Database will be created in the path and with the name as specified
       ' within the DBName Parameter. If no path is provided within the parameter
       ' then the Database will be created in the same folder of the application
       ' that Called this function.
       ' --------------------------------------------------------------------------
       ' PARAMETERS:
       ' ==========
       ' DBName:        Path and or File Name of the Database to create. Must
       '                contain at least the Database File Name to create.
       ' --------------------------------------------------------------------------
       ' RETURNS:
       ' ======
       ' TRUE if Successful
       ' FALSE if Unsuccessfull
       ' --------------------------------------------------------------------------
       Dim db As Database
       Screen.MousePointer = 11
       On Error Resume Next
       CreateBlankDatabase = False
       If InStr(DBName, "\") = 0 Then DBName = Application.CurrentProject.Path & "\" & DBName
       If InStr(UCase(DBName), ".MDB") = 0 Then DBName = DBName & ".mdb"
       If DoesFileExist(DBName) = True Then
          If MsgBox("Database Creation Error:  " & vbCrLf & vbCrLf & _
                     DBName & "The Database already exisits " & _
                     "in the location specified." & vbCrLf & "Do " & _
                     "you want to Delete this Database and try again?", _
                     vbCritical + vbYesNo, "DB Creation Error...") = vbYes Then
             Kill DBName
             If Err = 70 Or Err.Description = "Permission denied" Then
                MsgBox "Delete Permission Denied:  " & GetFileNameFromPath(DBName) & _
                        "The Database you are trying to delete is currently open." & _
                        vbCrLf & "Please Close this Database and try again.", _
                        vbCritical, "Delete Database Error..."
                Screen.MousePointer = 0
                Exit Function
                Err = 0
             End If
             GoTo ReTryCreateDB
          End If
          Screen.MousePointer = 0
          Exit Function
       End If
       Set db = DBEngine.CreateDatabase(DBName, dbLangGeneral)
       If Err > 0 Then
          Err = 0
          MsgBox "Database Creation Error:  " & GetFileNameFromPath(DBName) & _
                 "We were not permitted to created the specified Database " & _
                 "within the specified location. Please be sure permissions " * _
                 "have be set to allow for files to be saved to disk.", _
                 vbCritical, "Database Creation Error..."
          Screen.MousePointer = 0
          Exit Function
       End If
       CreateBlankDatabase = True
       If Not db Is Nothing Then db.Close
       Set db = Nothing
       Screen.MousePointer = 0
    End Function
    '  ////////////////////////////////////////////////////////////////////
    ' // Other Required Functions For The CreateBlankDatabase Function: //
    Public Function DoesFileExist(PathStrg As String) As Boolean
        If Len(Dir(PathStrg)) > 0 Then DoesFileExist = True
    End Function
    Public Function GetFileNameFromPath(PathStrg As String) As String
       Dim a$, i As Integer
       For i = Len(PathStrg) To 1 Step -1
          If Mid$(PathStrg, i, 1) <> "\" Then
             a$ = Mid$(PathStrg, i, 1) & a$
             Exit For
          End If
       Next i
       GetFileNameFromPath = a$
    End Function
    The file name provision you use is entirely up to you but off hand, I would make each one contain a unique name, perhaps using the current date and time as a file name. Here is how I would fire the above CreateBlankDatabase Function (in the OnClick event of a Command button or something):
    ' Declare a String variable to hold our unique
    ' file name
    Dim FileNameStrg As String
    ' Because you can't use the Forward Slash and Colon
    ' (which is contained within the Date/Time provided
    ' from VBA's built in Now() Function) within a file 
    ' name we convert these characters to a simple Dash
    ' (minus) character which is allowed. Spaces are
    ' converted to an Underscore character. We do all 
    ' this by recursing through VBA's built in Replace
    ' Function.
    FileNameStrg = Replace(Replace(Replace(Now, "/", "-"), ":", "-")," ","_") 
    ' Create the MDB file with the unique name we
    ' just generated.
    If CreateBlankDatabase(FileNameStrg) = True Then
      MsgBox "Database Creation Successfull!"
    End If
    Next, we export the database component (be it a Form, a Table, a Report, etc.) into the newly created MS-Access MDB file. Here is a Function you can use to do this:
    DoCmd.TransferDatabase acExport, "Microsoft Access", _
                      FileNameStrg, acForm, "Form Name", _
                      "Form Name", True
    Because this post is so long, it is in two segments. The following post is the continuation.

    Self Taught In ALL Environments.....And It Shows!

  3. #3
    Join Date
    Nov 2003
    Continued from the post above....

    Now, we need to mail the MDB file by way of an attchment with MS-Outlook. Here is a function to do this but before you use this you'll need to know that to use this code, you must first set a reference to the Outlook Object Library (in Access 2000 you can do this from the Tools | References menu option in the Visual Basic Editor {VBE}) - the file you're looking to reference is an OLB file, for example: msoutl9.olb for Outlook 2000.

    Again, place this code into a Database Code Module:
    Public Function EMailWithOutlook(Optional FromAddr, Optional Addr, Optional CC, Optional BCC, _
        Optional Subject, Optional MessageText, Optional AttachmentPath, Optional Vote As String = vbNullString, _
        Optional Urgency As Byte = 1, Optional EditMessage As Boolean = True)
       Dim objOutlook As Outlook.Application
       Dim objOutlookMsg As Outlook.MailItem
       Dim objOutlookRecip As Outlook.Recipient
       Set objOutlook = CreateObject("Outlook.Application") 'For conventional Access
       ' For Access runtime, use:
       ' Set objOutlook = CreateObject("Outlook.Application", "localhost")
      Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
       With objOutlookMsg
          If Not IsMissing(FromAddr) Then
             .SentOnBehalfOfName = FromAddr
          End If
          If Not IsMissing(Addr) Then
             Set objOutlookRecip = .Recipients.Add(Addr)
             objOutlookRecip.Type = olTo
          End If
          If Not IsMissing(CC) Then
             Set objOutlookRecip = .Recipients.Add(CC)
             objOutlookRecip.Type = olCC
          End If
          If Not IsMissing(BCC) Then
             Set objOutlookRecip = .Recipients.Add(BCC)
             objOutlookRecip.Type = olBCC
          End If
          If Not IsMissing(Subject) Then
             .Subject = Subject
          End If
          If Not IsMissing(MessageText) Then
             .Body = MessageText
          End If
          If Not IsMissing(AttachmentPath) Then
             'Check file exists before attaching!
            If DoesFileExist(AttachmentPath) = True Then
                Set objOutlookAttach = .Attachments.Add(AttachmentPath)
                MsgBox "The Specified Attachment Can Not Be Found!", vbExclamation
             End If
          End If
          If IsNull(Vote) = False Then
             .VotingOptions = Vote
          End If
          Select Case Urgency
             Case 2
               .Importance = olImportanceHigh
             Case 0
               .Importance = olImportanceLow
             Case Else
               .Importance = olImportanceNormal
          End Select
          For Each objOutlookRecip In .Recipients
          If EditMessage Then
          End If
       End With
       Set objOutlook = Nothing
    End Function
    Now, to put all this into play the code in our Command Button OnClick event might look like this:
    Private Sub Command1_Click()
       ' Declare Variables
       Dim FileNameStrg As String   ' Holds the Unigue FileName
       Dim FormName As String       ' Holds the name of Form we want to send.
       FormName = "The Form Name in Current DB"
       ' Generate a Unique File Name using Date & Time.
       FileNameStrg = Replace(Replace(Replace(Now, "/", "-"), _
                              ":", "-"), " ", "_") & ".mdb"
       ' Create the Blank Database...  
       If CreateBlankDatabase(FileNameStrg) = True Then
          ' Export the Desired Form
          DoCmd.TransferDatabase acExport, "Microsoft Access", _
                               FileNameStrg, acForm, FormName, _
                               FormName, True
          ' Now E-Mail the newly created MDB Database...
          ' Checking for an Internet Connection and
          ' Compressing (.zip) the MDB file can also be
          ' accomplished with VBA before E-Mailing but
          ' that's another topic all together.
         Call EMailWithOutlook("", ";;", , _
                                "New Form...", "Attached to this note is the newly modified Form (" & FormName & "). Simply Copy from the Attached MDB " & _
                                "file and paste it into your working MDB file.", FileNameStrg, , , True)
    End Sub for thought.

    Self Taught In ALL Environments.....And It Shows!

  4. #4
    Join Date
    Sep 2006

    Talking thanks a lot!!

    thank you for your reply... i will try this one! thanks a lot!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts