+ Reply to Thread
Results 1 to 5 of 5

Auto Populate Form With Selected Email In VBA Userform

  1. #1
    Registered User
    Join Date
    06-15-2014
    Posts
    5

    Auto Populate Form With Selected Email In VBA Userform

    Hello,

    I have a userform set up that when submitted populates a range in a database and emails the data to a recipient. Now the recipient is selected based on the day of the week and whether it is am/pm. As the email is going out to numerous recipients is it possible to auto populate a field in the form with the auto selected email so it can be recorded??

    Regards,
    Jeffrey

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Auto Populate Form With Selected Email In VBA Userform

    Yes - of course. You can do almost anything with VBA. How is the email selected?
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    06-15-2014
    Posts
    5

    Re: Auto Populate Form With Selected Email In VBA Userform

    The Code for populating the database is:

    ws.Cells(vNewRow, 1).Value = Format(Now, "dd/mm/yyyy hh:mm")
    ws.Cells(vNewRow, 2).Value = Me.formField2.Value
    ws.Cells(vNewRow, 3).Value = Me.formField3.Value
    ws.Cells(vNewRow, 4).Value = Me.formField4.Value
    ws.Cells(vNewRow, 5).Value = Me.formField5.Value
    ws.Cells(vNewRow, 6).Value = Me.formField6.Value
    ws.Cells(vNewRow, 7).Value = Me.formField7.Value
    ws.Cells(vNewRow, 8).Value = Me.formField8.Value
    ws.Cells(vNewRow, 9).Value = Me.formField9.Value
    ws.Cells(vNewRow, 10).Value = Me.formField10.Value
    ws.Cells(vNewRow, 1).Activate

    and the code for selecting the email recipient is:

    Select Case Weekday(Date)
    Case 1 '// Sunday
    .To = ""
    Case 2 '// Monday
    If CSng(Time()) <= 0.5 Then
    .To = ""
    Else
    .To = ""
    End If
    Case 3 '// Tuesday
    If CSng(Time()) <= 0.5 Then
    .To = ""
    Else
    .To = ""
    End If
    Case 4 '// Wednesday
    If CSng(Time()) <= 0.5 Then
    .To = ""
    Else
    .To = ""
    End If
    Case 5 '// Thursday
    If CSng(Time()) <= 0.5 Then
    .To = ""
    Else
    .To = ""
    End If
    Case 6 '// Friday
    .To = ""
    Case 7 '// Saturday
    .To = ""
    End Select

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Auto Populate Form With Selected Email In VBA Userform

    Your code is fine - where are the addresses that you want to use? If you list them in order Sunday AM, Sunday PM, Monday AM etc. in a range named EmailByDay, then you could use

    .To = Range("EmailByDay").Cells((Weekday(Date) - 1) * 2 + 1 + IIf(CSng(Time) < 0.5, 0, 1))

  5. #5
    Registered User
    Join Date
    06-15-2014
    Posts
    5

    Re: Auto Populate Form With Selected Email In VBA Userform

    Thanks for the help, good solution.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Auto populate form text box when item selected from a drop down
    By Wales MB in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-14-2012, 05:53 AM
  2. Auto populate a cell when 3 options are selected
    By dizzle in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-28-2011, 06:03 PM
  3. Auto Populate from PDF Form
    By CEDx in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2010, 08:45 AM
  4. Replies: 1
    Last Post: 01-22-2010, 03:57 PM
  5. Auto populate a form
    By clarkin in forum Excel General
    Replies: 0
    Last Post: 06-20-2007, 01:39 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1