Reply to comment

MS Access: Inserting Records with Visual Basic and DAO

This example shows you how to add records with VBA and DAO instead of with SQL queries. Sometimes, it's easier to do it this way.b (The original intent was to simultaneously create a relation between the new record and another table, but this didn't happen.)

Public Sub importFolks()
    Dim dbs As Database
    Dim rstFrom As Recordset
    Dim rstTo As DAO.Recordset
    Set dbs = CurrentDb()
    Set rstFrom = dbs.OpenRecordset("tmp match up list to db")
    Set rstTo = dbs.OpenRecordset("tblActivists", dbOpenDynaset, dbAppendOnly)
    a = 0
    Do Until (rstFrom.EOF)
        rstTo.Fields("Fname") = rstFrom.Fields("Field11")
        rstTo.Fields("Lname") = rstFrom.Fields("Field12")
        rstTo.Fields("Email") = Nz(rstFrom.Fields("email"))
        parts = ParsePhoneNumbers(Nz(rstFrom.Fields("Phone")), 1)
        rstTo.Fields("WCode") = parts(1)
        rstTo.Fields("WPhone") = parts(2)
        parts = ParsePhoneNumbers(Nz(rstFrom.Fields("FAX")), 1)
        rstTo.Fields("FCode") = parts(1)
        rstTo.Fields("Fax") = parts(2)
        rstTo.Fields("Cell") = rstFrom.Fields("cellNumber")
        a = a + 1
End Sub


The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.

More information about formatting options

6 + 5 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.