Results 1 to 11 of 11
  1. #1
    healey33 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    10

    E-mail hyperlink with pre-defined message

    Hey, I have a form with contact info (name, address, postal code, email etc.) and I have set up the e-mail as a hyperlink to outlook. I would like the hyperlink to not only start a new email to that person but also have text in the message field (a template). For example,
    "Hi, [Name]

    I would like to confirm your address of [Address] for delivery of a package.

    Thanks"



    Is something like this possible? The template would include much more text than this but if this works, I can do the template myself. If it is not possible to personalize the name and address automatically within the message, they can be entered manually in the message but ideally, I would like to do it automatically.

    Let me know if any more clarification is needed. Thanks in advance for any help.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Shouldn't be difficult. One method would be to use SendObject to create the email, and you can build a string using values from a form or whatever to use in the body argument. More info on SendObject in VBA help. Building the string would look like:

    strBody = "Hi " & Me.NameField & vbCrLf & VbCrLf & "I would like to confirm your address of " & Me.AddressField & " for delivery of a package."
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    healey33 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    10
    Thanks! That does almost exactly what I would like but it does not accept more than 255 characters. Is there a way around the character limit?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    I just did a brief test and it took 360 with no problem. What is your code? You may need to build the string over several lines, not all on one.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    healey33 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    10
    Ah yes. I had all of the string on the same line. It works perfectly, thanks!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Happy to help, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    healey33 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    10
    Thank you! How about this one? I would like to select all of the e-mail addresses from the "Email" column in a table named "Signed Leases" and display them in a label without duplicates (eventually I will send them all to outlook for a mass e-mail but i am displaying them for trial purposes). I am currently receiving an error message "Compile Error : Expected Array" at the "emails(count) =" line and I cannot see what is wrong!


    Code:
    Private Sub Command3_Click()
    Dim db As DAO.Database
    Dim strWhere As String
    Dim numberOfRecords As Integer
    Dim count As Integer
    Dim count2 As Integer
    Dim count3 As Integer
    Dim label As String
    Dim emails As String
    emails = Array()
    Dim emailsNoDuplicates As String
    emailsNoDuplicates = Array()
    Dim duplicate As Boolean
    Dim x As Integer
    x = 1
    label = ""
    
    
    
    
    Set db = CurrentDb ' select current database
    'numberOfRecords = DCount("[ID]", "Signed Leases") 'count number of records
    
    
    For count = 0 To 50 'first loop through
        strWhere = "ID = " & count + 1
        If DLookup("[Email]", "Signed Leases", strWhere) <> "" Then 'if the cell is not empty, populate the first array
            emails(count) = DLookup("[Email]", "Signed Leases", strWhere)
            duplicate = False 'reset duplicate to false
            For count2 = 0 To count - 1 'second loop for checking only previous entries
                If emails(count) = emails(count2) Then 'if the email has already been looked at, trigger duplicate to true
                duplicate = True
                End If
            Next count2
            If duplicate <> True Then 'if it is not a duplicate, populate a new array with the email
                emailsNoDuplicates(x) = emails(count2)
                x = x + 1
            End If
        End If
    Next count
    Text4.SetFocus
    For count3 = 0 To x - 1
        label = label & emailsNoDuplicates(count3) & "; "
        Text4.Text = label
    Next count3
    
    
    End Sub
    Any help is greatly appreciated!

  8. #8
    healey33 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    10
    Quote Originally Posted by healey33 View Post
    Dim x As Integer
    x = 1
    I realize this should be x = 0 but that is not the issue.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    That would be really inefficient. Try this type of thing:

    Code:
      Dim strSQL                  As String
      Dim db                      As DAO.Database
      Dim rs                      As DAO.Recordset
      Dim strAddys                As String
    
      Set db = CurrentDb()
    
      strSQL = "SELECT DISTINCT Email FROM [Signed Leases] WHERE Email Is Not Null"
      Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    
      Do While Not rs.EOF
        strAddys = strAddys & rs!Email & "; "
        rs.MoveNext
      Loop
      MsgBox strAddys
    
      Set rs = Nothing
      Set db = Nothing
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    healey33 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    10
    Well that makes things a little easier! Thank you very much! How would I add other restrictions to this? for example I have a city field with about 12 different cities and would like to display the e-mail addresses within just one city (Toronto for example). Is it possible to add more parameters to this function?

    Thanks again, I am still very new to Access and VBA.

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    strSQL is simply an SQL statement (a query) and could contain any number of parameters. You can even open the recordset on a saved query, though if it has form parameters you'll have an issue. You can create a query that does what you want and then use it directly or copy the SQL into the code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Hyperlink email won't mail-merge
    By alexc333 in forum Access
    Replies: 1
    Last Post: 09-20-2011, 07:17 PM
  2. Mail Merge: Clickable Hyperlink
    By Sandi in forum Access
    Replies: 3
    Last Post: 09-20-2011, 12:36 PM
  3. Application-defined or object-defined error
    By hawkins in forum Access
    Replies: 6
    Last Post: 07-01-2011, 01:57 PM
  4. Replies: 4
    Last Post: 01-31-2011, 03:19 PM
  5. Error: "User-defined type not defined"
    By mastromb in forum Programming
    Replies: 10
    Last Post: 01-08-2010, 02:57 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums