Consulting

Results 1 to 8 of 8

Thread: Solved: Assistance with email SendTo (xl '97)

  1. #1
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location

    Solved: Assistance with email SendTo (xl '97)

    Hi,

    I currently have the following code :
    [VBA]SendTo = Array(address1@nospam.com, "address2@nospam.com", "address3@nospam.com")[/VBA]
    Is it possible to change the above to be built based on the values from several User form textboxes?
    For example (which doesn't work):
    [VBA]Dim strArray As String
    strArray = txtbox1.value & ", " & txtbox2.value & ", " & txtbox3.Value
    SendTo = strArray[/VBA]
    The email is being sent via Lotus Notes and not Outlook.
    Would anyone be able to offer any suggestions?
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi Phendrena :-)

    Assuming the top one works, maybe this will help(?). Since you know how many textboxes you have, you could do like...

    [vba]
    Option Explicit

    Sub ary()
    Dim a, b, c
    Dim ary(0 To 2)
    Dim SendTo
    Dim i As Long

    '// a, b, and c represent the textboxes
    a = "address1@nospam.com"
    b = "address2@nospam.com"
    c = "address3@nospam.com"

    ary(0) = a
    ary(1) = b
    ary(2) = c

    SendTo = ary

    For i = LBound(ary) To UBound(ary)
    MsgBox ary(i)
    Next
    End Sub
    [/vba]

    This will not compensate for empty textboxes though, so you may wish to increase the array's size (ReDim Preserve) as you go through the textboxes, or, only act upon elements of the array that have a value in them.

    Hope that helps,

    Mark

  3. #3
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    Hi Mark,

    Yes the first example does work.

    Thanks,
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    My apologies,

    I thought (silly me, with as slow as I type) that I could get away with editing my first post (at #2).

    For others: I did ask whether the first code (in #1) worked, then edited to the current...

    Shame on me...

    Mark

  5. #5
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    AAACKKK!!!

    That is supposed to be:
    [vba]
    For i = LBound(SendTo) To UBound(SendTo)
    [/vba]
    ...for the example, on top of which I forgot to say that you can simply build/size SendTo the same way.

    My bad, way to tired...

    Mark

  6. #6
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    Quote Originally Posted by GTO
    [vba] '// a, b, and c represent the textboxes
    a = "address1@nospam.com"
    b = "address2@nospam.com"
    c = "address3@nospam.com"

    ary(0) = a
    ary(1) = b
    ary(2) = c [/vba]
    Where you say that a, b & c represent the texboxes, do i need to change the a, b, c to the names of the textboxes or the value after the = to the textbox?

    Thanks,
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  7. #7
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Dear Phedrena,

    Sorry for such a terrible example. The values shown to the right of the equal signs would be replaced with txtbox"x".Value, where "x" is the number of the textbox.

    I am off to hit the sack, as obviously my "thinker" has shut down.

    Maybe this will seem more sensible:
    [vba]
    Sub exa()
    '// Size SendTo based on how many textboxes there are //
    Dim SendTo(0 To 2)
    '// just for a counter //
    Dim i As Long

    '// fill the three elements in SendTo with the vals from the textboxes //
    SendTo(0) = txtbox1.Value '"address1@nospam.com"
    SendTo(1) = txtbox2.Value '"address2@nospam.com"
    SendTo(2) = txtbox3.Value '"address3@nospam.com"

    '// Then use L and U Bound to loop thru //
    For i = LBound(SendTo) To UBound(SendTo)
    If InStr(1, SendTo(i), "@", vbTextCompare) > 0 Then
    MsgBox "Do something here with: " & SendTo(i)
    End If
    Next
    End Sub

    [/vba]

    A great day to you and yours,

    Mark

  8. #8
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    Thank Mark.
    That'll do nicely
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

Posting Permissions

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