CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2001
    Posts
    1

    Creating a new record in an Access DB using Visual Basic

    Hey all --

    I'm having a problem finding the function to create a new record in an Access DB using the Click event of a command button. I have read the post about disconnecting and reconnecting to add a field, but i just need to know the way to add a record. Any help will be appreciated.

    Thanks


  2. #2
    Join Date
    Nov 2000
    Location
    Ohio
    Posts
    238

    Re: Creating a new record in an Access DB using Visual Basic

    Using ADO..

    Private Sub Command1_Click()

    Dim Conn As ADODB.Connection
    Dim sConn As String
    Dim rs As ADODB.Recordset

    Set Conn = New ADODB.Connection

    sConn = "DSN=YourDSNNAME"
    Conn.ConnectionString = sConn
    Conn.CursorLocation = adUseServer
    Conn.Open

    Set rs = New ADODB.Recordset
    rs.ActiveConnection = Conn

    rs400.Open "SELECT * FROM YourTable", Conn, adOpenDynamic, adLockOptimistic

    rs.Addnew
    rs!FieldName1 = "your new value"
    rs!FieldName2 = "your new value"
    rs.Update

    rs.close
    Conn.close

    Set rs = nothing
    Set Conn = nothing

    End Sub


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured