I'm trying to insert a string into a field in a table using vba but I can't seem to get it. I'm not use to Access VBA but have some experience with Excel.
I'm using cr to find my current record of my form, and em to find the e-mail addresses I want to find.
the debug gets exactly what I want, but I can't get it to put it into the table ( cr.Fields("ToAddress") = AllAddress )
HTML Code:Dim ToAdd As String Dim em As DAO.Recordset Dim CurRecord As String Dim cr As DAO.Recordset Dim RecSet As Integer Dim AllAddress As String ToAdd = "tblContacts" CurRecord = "tblEmail" Set em = CurrentDb.OpenRecordset(ToAdd) Set cr = CurrentDb.OpenRecordset(CurRecord) With cr If Not .BOF And Not .EOF Then .MoveLast .MoveFirst While (Not .EOF) If cr.Fields("EmailID") = Forms!frmEmail!EmailID Then ' Debug.Print cr.Fields("EmailID") '--------- Add E-Mails to the current record.----------------------------------------------------------------------------------------------------------------- With em If Not .BOF And Not .EOF Then .MoveLast .MoveFirst While (Not .EOF) If em.Fields("MailingList") = -1 Then ' Debug.Print em.Fields("Email") & ";" AllAddress = AllAddress & em.Fields("Email") & ";" End If .MoveNext Wend End If End With Debug.Print AllAddress cr.Fields("ToAddress") = AllAddress '--------- Add E-Mails to the current record.----------------------------------------------------------------------------------------------------------------- End If .MoveNext Wend End If .Close End With
Bookmarks