Adding data to table using forms.

Posted on 2006-04-06
Last Modified: 2010-04-17
I am three fields in "Table1". I created a form with three textbox exactly like the ones used as field heading in "Table" 1.I also added a button that is supposed to add records to "Table1" when clicked. I am very new to access coding. Someone please help me write code to this button so that I can populate the table using form


Field1   Field2   Field3(combo with valued 1,2,3)


Field1 ________
Field3________            AddButton.

Thank you.
Question by:Aiysha
    LVL 28

    Accepted Solution

    Here is a simple example in VB. Maybe it can help:

    ' add a reference to Microsoft ActiveX Data Objects Library:
    Dim DataBase As String
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset

    Private Sub Form_Load()
    DataBase = "C:\MyDataBase.mdb"

    ' open Database Connection
    Set cn = New ADODB.Connection
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & DataBase & "'"
    cn.CursorLocation = adUseClient

    ' open recordset
    Set rs = New ADODB.Recordset
    rs.Open "Select * From YourDBTableName", cn, adOpenKeyset, adLockOptimistic

    End Sub

    Private Sub Command1_Click()
    ' add new record to Table
    rs.Fields("Field1").Value = Field1.Text
    rs.Fields("Field2").Value = Field2.Text
    rs.Fields("Field3").Value = Field3.Text

    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    ' close recordset
    Set rs = Nothing

    ' close connection
    Set cn = Nothing
    End Sub

    LVL 28

    Expert Comment

    Just replace YourDBTableName with Table1 and it should work.
    LVL 5

    Expert Comment


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
    A short article about problems I had with the new location API and permissions in Marshmallow
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now