Results 1 to 4 of 4

Thread: SendObject

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    4

    Question SendObject

    I'm using SendObject method to send a data where i fetch from a table. The problem i'm facing rite now is I just can send the mail only once. In my form I have 2 textboxes, 1 for E-mail subject the other one is for the message box, 2 command buttons 1 for fetching data from table to put into the msg box and the other one for sending. Below is the code

    Fetching data
    Private Sub Command2_Click()
    Dim dbs As Database
    Dim rst As DAO.Recordset



    Set dbs = CurrentDb()
    Set rst = dbs.OpenRecordset("MyTable")

    '// MSG1 is Text Box for Message body

    Do While Not rst.EOF
    Me.MSG1.Value = Me.MSG1.Value & rst!Filed1 & " " & rst!Field2 & " " & "verified by " & rst!Field3 & " (" & rst!Field4 & ")" & Chr(13) + Chr(10)
    Me.MSG1.ScrollBars = 2
    rst.MoveNext
    Loop

    rst.close

    End Sub

    Sending E-mail


    Private Sub Command3_Click()
    Dim MSG, subj2 As String

    MSG = Me.MSG1.Value
    subj2 = Me.Subject1.Value
    DoCmd.SendObject acSendNoObject, , , "receiver", , , subj2, MSG, False


    pls help me

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Can't you just put it in a loop? If two different email recipients, skip the loop and send twice.
    VB Code:
    1. Private Sub Command3_Click()
    2. Dim MSG, subj2 As String
    3. dim i as integer
    4.  
    5. MSG = Me.MSG1.Value
    6. subj2 = Me.Subject1.Value
    7.  
    8. For i = 1 to 2
    9. DoCmd.SendObject acSendNoObject, , , "receiver", , , subj2, MSG, False
    10. Next
    11. 'or if skipping loop
    12. DoCmd.SendObject acSendNoObject, , , "other_receiver", , , subj2, MSG, False

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    4
    Hi salvelinus,

    I need to send to same group but different msg. Now If wanna send again with a different msg i have to quit access and run back the application. If not the second I want to use it the button is useless. Need ur help man... btw thanks a lot with ur last suggestion.

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Instead of getting the recordset in a Click event, put it in a separate function. Add a parameter to the new function to check which recordset should be retrieved, then call the new function twice from the Click event with different arguments.
    VB Code:
    1. Private Sub command1_click()
    2.   GetData(1)
    3.   Getdata(2)
    4. End Sub
    5.  
    6. Private Sub GetData(i as integer)
    7.   Dim dbs As Database
    8.   Dim rst As DAO.Recordset
    9.  
    10.   if i = 1 then
    11.     Set dbs = CurrentDb()
    12.     Set rst = dbs.OpenRecordset("MyTable")
    13.  
    14.     '// MSG1 is Text Box for Message body
    15.  
    16.     Do While Not rst.EOF
    17.       Me.MSG1.Value = Me.MSG1.Value & rst!Filed1 & " " & rst!Field2   & " " & "verified by " & rst!Field3 & " (" & rst!Field4 & ")" & Chr(13) + Chr(10)
    18.       Me.MSG1.ScrollBars = 2
    19.       rst.MoveNext
    20.     Loop
    21.  
    22.     rst.close
    23.   Else
    24.     'Do what you need to get the other data
    25.   End If
    26.  
    27.   DoCmd.SendObject acSendNoObject, , , "receiver", , , subj2, MSG, False
    28. End Sub

    Filling your textbox may be able to be moved out of the If statement if you're filling the same box with the same indexed fields of either recordset. In that case just put the code to create the 2nd recordset in the else statement.

Posting Permissions

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



Click Here to Expand Forum to Full Width