Results 1 to 2 of 2
  1. #1
    bhanu is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    1

    Inserting data into Access database

    Hi Everyone

    I started learning MS Access recently and started building a form to insert data into the database.I have a table tblPeople with columns peopleID,FirstName,LastName,Gender,Email,Phone. and the forms with the textboxes txtFirstName,txtLastName,txtGender,txtEmail,txtPho ne .I have return the code but am not knowing it is neither giving me any error message or inserting the data...below is the code I have return..Any help for me is very well appreciated...
    Private Sub btnRegister_Click()


    On Error GoTo Err_btnRegister_Click

    Dim cn As ADODB.Connection, rs As ADODB.Recordset
    Dim db As database
    Dim cmd As ADODB.Command
    Dim StringSql As String
    Set cn = New ADODB.Connection
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;", "Data Source=C:\MyFolder\Registration.mdb"

    Set db = OpenDatabase("C:\MyFolder\Registration.mdb")
    Set StringSql = "INSERT INTO tblPeople (FirstName, LastName, Gender, Email, Phone ) VALUES ('" & Me!txtFirstName.Value & "', '" & Me!txtLastName.Value & "', '" & Me!txtGender.Value & "', '" & Me!txtEmail.Value & "', '" & Me!txtPhoneNumber.Value & "');"
    cmd.RunSQL StringSql
    Set db = Nothing
    Set StringSql = Nothing


    Exit_btnRegister_Click:
    Exit Sub

    Err_btnRegister_Click:
    MsgBox Err.Description
    Resume Exit_btnRegister_Click

    End Sub

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    major conceptual issue here..... just source the form on the table....and then the "insert" is complete by definition....

    you have your table; go to Forms, select 'New', and then select Form Wizard...and instruct it to use your table as the record source......that's it.

    you don't need to do what you are attempting to do....which appears to be an unbound form and then an insert statement.....

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 05-14-2009, 12:34 AM
  2. Replies: 1
    Last Post: 02-10-2009, 09:57 PM
  3. Inserting data through forms
    By nivi30 in forum Forms
    Replies: 1
    Last Post: 12-17-2008, 07:57 AM
  4. Inserting data in new colums
    By wasim_sono in forum Queries
    Replies: 2
    Last Post: 02-28-2006, 01:11 AM
  5. Inserting Picture in MS Access Message
    By wasim_sono in forum Programming
    Replies: 0
    Last Post: 01-17-2006, 03:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums