Results 1 to 5 of 5
  1. #1
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91

    Cool Send email to customer from Form, where customer's email data is not in Form data source

    Click image for larger version. 

Name:	customer_related_email.PNG 
Views:	10 
Size:	43.5 KB 
ID:	44946

    In this form, you can see the Customer control combobox with the control source of cust_nb. That cust_nb is a foreign key in the form's record source that is related to the Customer table, where cust_nb is the primary key. This table contains the customer's email. I would like for the email button next to the combobox to just launch an Outlook message with the customer's email address populated. I can think of ways to do this that involve an intermediary step - launching a form or query that find the related record and then emailing from there - but I'd like to bypass that and just launch directly into the email step from this form.

    I imagine best route forward would be constructing a query in VBA on the button control that finds the related email and then launches the Email process with the email as an argument, but I've never written VBA that contains a SQL section. Could someone point me in the direction of how to run a SQL Select statement inside of a VBA sub to get that information to pass as an argument?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    grab the customers email addr from their table via combo box that IS bound to the client table
    cbo fields: CLientID, ClientName, ClientEmail

    add an unbound box, txtEmail to the form and fill it when user picks the Client from the combo.

    NOTE: in vb, columns begin with zero.
    Code:
    sub cboClient_afterupdate()
    txtEmail = cboClient.Column(2)  'col 3
    end sub


    now you can email using the txtbox.
    DoCmd.SendObject acSendQuery, "qsQuery", acFormatXLS, txtEmail, , , "Subject", "message"

  3. #3
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91
    Code:
    Public Sub btnEmail_Click()
        Dim email_target As String
        email_target = DLookup("email", "tblCustomers", "customerNumber = '" & Forms!frmRMA!cust_nb) & "'"
        'DoCmd.SendObject acSendNoObject,,,email_target,,,"RMA example",,True)
    End Sub
    I have begun to try to solve using a common method I've found online, DLookup. However I'm getting a Run-time error '3075': "Syntax error in string in query expression 'customerNumber = 'FULSTEA'

    Can't figure out why

    ranman256, I may try your method if this ultimately fails, but I'd rather keep data processing functions out of the form design and instead contained in the VBA back-end of it.

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Can you try to enclose the field and table names in square brackets? Also you have the parenthesis in the wrong spot:
    Code:
    DLookup("email", "tblCustomers", "customerNumber = '" & Forms!frmRMA!cust_nb & "'")
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91
    Quote Originally Posted by Gicu View Post
    Can you try to enclose the field and table names in square brackets? Also you have the parenthesis in the wrong spot:
    Code:
    DLookup("email", "tblCustomers", "customerNumber = '" & Forms!frmRMA!cust_nb & "'")

    Moving parenthesis did the trick. It's always the dumb little things ya don't see when you're caught up in the weeds!

    I now have it displaying the related email in a message box so I can test it out with various customers.

    Now to get the DoCmd working!

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

Similar Threads

  1. Send Form Data in Email
    By DSProductionz in forum Forms
    Replies: 9
    Last Post: 10-11-2018, 08:39 AM
  2. Replies: 3
    Last Post: 12-28-2015, 04:11 PM
  3. Replies: 1
    Last Post: 03-23-2015, 05:59 PM
  4. how can i send email to the current customer
    By gstylianou in forum Access
    Replies: 4
    Last Post: 06-12-2014, 12:42 PM
  5. Email Each Invoice to each customer
    By snehal0909 in forum Database Design
    Replies: 2
    Last Post: 06-12-2012, 02:27 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