Results 1 to 3 of 3
  1. #1
    linoreale is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Oct 2014
    Posts
    10

    append records to a table from recordset

    Ciao,
    I have the code below that sends email from access:

    Dim db As Database, RS As Recordset
    Set db = CurrentDb
    Set RS = db.OpenRecordset("prova", dbOpenDynaset)
    ' q_invio_email

    If RS.RecordCount = 0 Then
    MsgBox "Nessun messaggio da inviare!" & vbCrLf _
    & "Probabilmente non sono stati selezionati i medici curanti nella richiesta " _


    & "o sono state valutate solo proroghe."
    Exit Sub
    End If

    'istruzioni per il conteggio dei record
    RS.MoveLast
    rstotale = RS.RecordCount

    'msgbox per procedere con l'invio
    msg = MsgBox("Si desidera inviare " & rstotale & " messaggi email relativi all'esito della seduta del " _
    & RS!data_valutazione, vbYesNo)
    If msg = vbNo Then
    Exit Sub
    Else


    ' Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
    Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
    ' Const cdoAnonymous = 0 'Do not authenticate
    Const cdoBasic = 1 'basic (clear-text) authentication
    Const cdoNTLM = 2 'NTLM

    ' Da qui comincia il ciclo
    RS.MoveFirst
    Do Until RS.EOF

    Set objmessage = CreateObject("CDO.Message")


    objmessage.BodyPart.Charset = "utf-8"
    objmessage.Subject = "Seduta U. V. M. del " & RS!data_valutazione
    objmessage.From = """PUA NOD di xxx"" <prova@prova.it>"
    objmessage.To = RS!EMail
    objmessage.TextBody = "Gentile dott. " & RS!cognomenome & "," & vbCrLf _
    & "in data " & RS!data_valutazione _
    & " si è riunita l'Unità di Valutazione Multidimensionale (UVM) di xxx" _
    & "che ha esaminato la Sua richiesta riferita al paziente " & RS!Cognome & " " & RS!Nome _
    & " con il seguente esito: " & vbCrLf & Chr(34) & RS!esito & Chr(34) & "." & vbCrLf _
    & "Pertanto la S. V. è invitata a dare seguito, per competenza, nel più breve tempo possibile, " _
    & "considerati i termini previsti dal DCA n. 107/13." & vbCrLf _
    & "Cordiali Saluti" & vbCrLf & vbCrLf _
    & "Il PUA del NOD di xxxx"

    '==This section provides the configuration information for the remote SMTP server.

    objmessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/con...tion/sendusing") = 2

    'Name or IP of Remote SMTP Server
    objmessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/con...ion/smtpserver") = "smtp.miosmtp.it"

    'Type of authentication, NONE, Basic (Base64 encoded), NTLM
    objmessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/con...tpauthenticate") = cdoBasic

    'Your UserID on the SMTP server
    objmessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/con...n/sendusername") = "miamail@miosito.it"

    'Your password on the SMTP server
    objmessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/con...n/sendpassword") = "password"

    'Server port (typically 25)
    objmessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/con...smtpserverport") = 25

    'Use SSL for the connection (False or True)
    objmessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/con...ion/smtpusessl") = False

    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    objmessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/con...nectiontimeout") = 30

    objmessage.Configuration.Fields.Update

    '==End remote SMTP server configuration section==

    ' invio del messaggio
    objmessage.Send

    ' accoda il record corrente nella tabella pua_email_inviate per il controllo successivo
    DoCmd.RunSQL "INSERT INTO pua_email_inviate SELECT cognomenome,email from rs"

    RS.MoveNext
    Loop
    End If

    MsgBox "Inviati " & rstotale & " messaggi email!"

    RS.Close
    Set RS = Nothing
    Set db = Nothing



    I created a table pua_email_inviate where I want to append each current record is sending via mail, then I added that rows as in the code:


    ' accoda il record corrente nella tabella pua_email_inviate per il controllo successivo
    DoCmd.RunSQL "INSERT INTO pua_email_inviate SELECT cognomenome,email from rs"

    but it doesn't append because I don't know how to identify the current record in the code (I putted From rs but it's wrong)
    Everything else works fine.
    Can you help me please?
    Regards


    __
    Remigio










  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Save the sql to a querydef. Then run an append query that uses this query to append.

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Try:

    CurrentDb.Execute "INSERT INTO pua_email_inviate(cognomenome, email) VALUES('" & rs!cognomenome & "', '" & rs!email & "')"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 08-01-2013, 06:04 AM
  2. Replies: 3
    Last Post: 02-05-2013, 05:07 PM
  3. Replies: 2
    Last Post: 05-21-2012, 08:46 PM
  4. Replies: 5
    Last Post: 12-12-2011, 08:08 AM
  5. Append table elements as new records
    By bkirsch in forum Forms
    Replies: 1
    Last Post: 11-16-2011, 01:55 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