Access VBA

css navigation by Css3Menu.com

Write from Recordset

I always struggled with RecordSet. The syntax was bewildering to me. Finally I saw what my friend was doing any became hooked.
Private Sub cmdSaveCurRecord_Click()
On Error GoTo Err_cmdSaveCurRecord_Click

    Dim SQLstring       As String
    Dim myTable         As Recordset
    
    Set myTable = CurrentDb.OpenRecordset("MailingList")
   '  Set the recordSet
        With myTable
            .AddNew
            !First = Me.FirstName   ' Table items
            !Last = Me.LastName
            !Street = Me.StreetAddr
            !City = Me.City
            !State = Me.StateProv
            !Zip = Me.ZipCode
            !Priority = Me.Priority
            !Email=Me.EmailAddr
            !Exhb = Me.ExhibClass
            !Phone = Me.HomePhone
            !altkphone = Me.BizPhone
            .Update         ' Update it
        End With
        myTable.Close       ' Close to release memory
        

Exit_cmdSaveCurRecord_Click:
    Exit Sub

Err_cmdSaveCurRecord_Click:
    MsgBox Err.Description
    Resume Exit_cmdSaveCurRecord_Click
    
End Sub


My latest project uses lots of RecordSets to post to tables and SQL to get the data back out.

See the picture below for the dialog in from of this code.

RecordSet

© 2008-2017

Updated:  12/10/2017 15:42
This page added:  09 August 2008