Wrox Programmer Forums
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 30th, 2004, 10:40 AM
Registered User
Join Date: Jun 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to AlForum29 Send a message via Yahoo to AlForum29
Default Add Record to table from form

I have a form that runs docmd.openform "formName",,,"filterUsed" to open a new form with the record I want. Now I want to be able to change 2-4 fields and add the record as a new record. I have tried DoCmd.GoToRecord , , acNewRec but this blanks out the form. Please help...thank you.

Old July 1st, 2004, 04:59 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts

A little ADO should get it. Just list all the data entry controls on your form following the rst.AddNew method.

Private Sub cmdAdNew_Click()

    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim strSQL As String

    Set cnn = CurrentProject.Connection

    Set rst = New ADODB.Recordset
    strSQL = "SELECT FirstName, LastName FROM Employees"
    rst.Open strSQL, cnn, adOpenKeyset, adLockOptimistic

    With rst
        !FirstName = txtFirstName
        !LastName = txtLastName
    End With

    rst.Close: Set rst = Nothing
    cnn.Close: Set cnn = Nothing

End Sub

Here I'm just saving the first and last name fields displayed on the form as a new record in the form's recordsource.



Old January 2nd, 2013, 09:46 PM
Registered User
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Append records from a database to another

how can i append searched records from a data base file (access) to another data base file with similar structure.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add record form bunkerbang Access VBA 5 September 12th, 2007 12:17 AM
Add record to another table with radiobutton Dejitan ASP.NET 1.0 and 1.1 Basics 8 January 11th, 2007 09:24 AM
add a record to yes/no control form VB carlos1972 Access VBA 2 April 6th, 2006 10:01 PM
ADO record copy and add to table Freddyfred Access 2 February 16th, 2005 10:36 PM
Error 3201: Cannot add record in child form/table HomeShow Access VBA 0 October 5th, 2004 09:56 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.