Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Danzig's Avatar
    Danzig is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    Socal
    Posts
    29

    Email clickable button

    Hey everyone,

    I am trying to get this stubborn button to work. It works on the sample database that came with the Access 07 bible, but for some odd reason, it wont work on mine... I copy/pasted the code, changed everything accordingly, but somehow it still doesn't work. I am stuck. can anyone elaborate? am I going about this the right way?

    Note: I do have an Email field in my form. I also have a "Client Email" field that is where I want this button to email.



    below is the code I currently have on the button:

    Option Compare Database
    Option Explicit
    Private Sub cmdContact_Click()
    Call AddContact( _
    Me.Client, Me.LastName, Me.Address, _
    Me.City, Me.State, Me.PostalCode, Me.Email)
    End Sub
    Private Sub cmdEmail_Click()
    Call SendEmail(Me.Email)
    End Sub
    Private Sub Email_Change()
    Call HandleEnabling(Me.Email.Text, Me.Client)
    End Sub
    Private Sub Client_Change()
    Call HandleEnabling(Me.Email, Me.Client.Text)
    End Sub
    Private Sub Form_Current()
    Call HandleEnabling(Me.Email, Me.Client)
    End Sub
    Private Sub HandleEnabling( _
    varEmail As Variant, varClient As Variant)
    cmdEmail.Enabled = Len(varEmail & "") > 0
    ' cmdContact.Enabled = Len(varClient & "") > 0
    End Sub

  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,521
    Can you elaborate on "it doesn't work"? Error? If so, what is it and on what line? Wrong result?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Danzig's Avatar
    Danzig is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    Socal
    Posts
    29
    I had it so the button was clickable, but it wouldn't open outlook (Google code). Then I got the MS Access bible that came with a sample database, which has an email button that does open outlook. At that point I decided to abandon the google code & just copy the code from the sample database. Since then, the button is greyed out, and is not even clickable.

    I dont know much about VBA, so I was hoping someone would see a problem with my code, and point it out.

  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,521
    Is there something in the email field? Is code running at all (is the db in a Trusted Location or has code been explicitly enabled)?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Danzig's Avatar
    Danzig is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    Socal
    Posts
    29
    when I click the button now it says "Compile Error: User-defined type not defined"

  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,521
    What line does it highlight?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Danzig's Avatar
    Danzig is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    Socal
    Posts
    29
    Here is what it looks like on my side. The red is where it was highlighted in grey. Not sure what the colors mean. I am still trying to learn vb. I have been reading the book, but can only read so fast.

    Is there any way I can email each form quickly in the meantime? Or do I need to printscreen into word every time?

    Option Compare Database
    Option Explicit

    ' InitOutlook sets up outlookApp and outlookNamespace.
    Private outlookApp As Outlook.Application
    Private outlookNamespace As Outlook.NameSpace
    Private Sub InitOutlook()
    ' Initialize a session in Outlook
    Set outlookApp = New Outlook.Application

    'Return a reference to the MAPI layer
    Set outlookNamespace = outlookApp.GetNamespace("MAPI")

    'Let the user logon to Outlook with the
    'Outlook Profile dialog box
    'and then create a new session
    outlookNamespace.Logon , , True, False
    End Sub

    Private Sub CleanUp()
    ' Clean up public object references.
    Set outlookNamespace = Nothing
    Set outlookApp = Nothing
    End Sub
    Public Sub AddContact(varFirstName As Variant, varLastName As Variant, _
    varAddress As Variant, varCity As Variant, varState As Variant, _
    varPostalCode As Variant, varEmail As Variant)
    Dim item As Outlook.ContactItem

    InitOutlook
    Set item = outlookApp.CreateItem(olContactItem)
    item.FirstName = varFirstName & ""
    item.LastName = varLastName & ""
    item.HomeAddressStreet = varAddress & ""
    item.HomeAddressCity = varCity & ""
    item.HomeAddressState = varState & ""
    item.HomeAddressPostalCode = varPostalCode & ""
    item.Email1Address = varEmail & ""
    item.Display

    CleanUp
    End Sub
    Public Sub SendEmail(varTo As Variant)
    Dim mailItem As Outlook.mailItem

    InitOutlook
    Set mailItem = outlookApp.CreateItem(olMailItem)
    mailItem.To = varTo & ""
    mailItem.Subject = "Message for Access Contact"
    mailItem.Display

    Set mailItem = Nothing
    CleanUp
    End Sub

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That code requires a reference to the Outlook object library in Tools/References. That's where your error comes from. The other colors are normal. Green is a comment line. They don't execute, they're just there to help document the code. The blue are recognized key words.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Danzig's Avatar
    Danzig is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    Socal
    Posts
    29
    tools/referances in outlook? or tools/ref in access?

  10. #10
    Danzig's Avatar
    Danzig is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    Socal
    Posts
    29
    I found tools, but References is greyed out & wont let me click.

  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,521
    In the Access VBA editor. That will present you with a listbox with all available references. You'd scroll down and check the MS Outlook... option, whichever version you have.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    Danzig's Avatar
    Danzig is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    Socal
    Posts
    29
    how do I display the design of an existing module? Or do I need to create a new one?

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The code? You should be able to double click on it in the Project Explorer window along the left side.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    Danzig's Avatar
    Danzig is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    Socal
    Posts
    29
    I double clicked, and still wont let me choose references. Any other ideas?

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you post the db?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Email button.
    By emccalment in forum Access
    Replies: 3
    Last Post: 02-19-2010, 04:14 PM
  2. Replies: 6
    Last Post: 02-09-2010, 07:53 AM
  3. Access email button messing up numbers
    By ninjafly in forum Reports
    Replies: 3
    Last Post: 08-20-2009, 04:27 AM
  4. email contact button
    By nwalke in forum Programming
    Replies: 3
    Last Post: 07-02-2009, 07:11 AM
  5. email button in form
    By peterinbristol in forum Forms
    Replies: 0
    Last Post: 03-19-2007, 02:25 PM

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