CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2006
    Location
    Northern Ontario
    Posts
    20

    Help with database

    I am really stuck right now. How do you start with an empty recordset and the program add a record when the program launches. I have tried the simple:
    Data1.RecordSet.AddNew, but I get 'Error 91'.

    I would really appreciate if someone could help me with this.

    Thx!!!
    Perfection is flaw.....

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Help with database

    Post your code. Bound controls are harder to work with
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    May 2006
    Location
    Northern Ontario
    Posts
    20

    Re: Help with database

    I would post my code but I don't really have any working code. I would simply like to know how to have the program start a new record on runtime. My recordset will be empty when the program first loads.

    Also, I was wondering if there is any good source out there where I could full instructions on how access databases work.

    Thx!!
    Perfection is flaw.....

  4. #4
    Join Date
    Dec 2007
    Posts
    21

    Re: Help with database

    To insert new record, you can try to use SQL statement

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Help with database

    You should create the table first in Access, but you don't need to add records.

    You could delete all records when the program starts as well.

    Read about SQL
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    May 2005
    Location
    Sterling Heights, MI
    Posts
    74

    Re: Help with database

    Here is a good start.

  7. #7
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487

    Re: Help with database

    i think the code below is a good one to start with, ADO (http://www.w3schools.com/ado/ado_intro.asp).. just read the comments to know what the code is doing..

    Code:
    Option Explicit
    
    Dim m_cn As ADODB.Connection
    Dim m_rs As ADODB.Recordset
    
    ' open connection/recordset
    Private Sub Form_Load()
      
      Set m_cn = New ADODB.Connection
      m_cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=<MDB filename>;"
        
      Set m_rs = New ADODB.Recordset
      m_rs.Open "SELECT * FROM <table name>", m_cn, adOpenKeyset, adLockOptimistic
    
    End Sub
    
    
    ' close connection/recordset
    Private Sub Form_Unload(Cancel As Integer)
      m_rs.Close
      Set m_rs = Nothing
      m_cn.Close
      Set m_cn = Nothing
    End Sub
    
    
    ' add one record
    Private Sub Command1_Click()
      
      m_rs.AddNew
      m_rs("field1").Value = "value1"
      m_rs("field2").Value = "value2"
      m_rs("fieldN").Value = "valueN"
      m_rs.Update
    
    End Sub
    Last edited by Thread1; December 21st, 2007 at 02:03 AM.
    Busy

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