Results 1 to 4 of 4

Thread: addnew record to recordset - performance issue

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    Question addnew record to recordset - performance issue

    Hi,

    I have a large ms access table and would like to add new record to it from an unbound form.

    Currently this is the code:

    set rst= currentdb.openrecordset ("table1")
    rst.addnew
    rst!id= myID
    rst!name= myname
    rst.update

    Thing is that opening the record set is very slow (again a big table).

    any ideas how to improve performance on this?

    Thanks!

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: addnew record to recordset - performance issue

    The quickest way is to not open a recordset (which copies all of the records from disk to memory), instead just add the record(s) directly to the table.

    I'm not sure of the DAO methods, but I think this is right:
    Code:
    Dim strSQL as String
      strSQL = "INSERT INTO table1 ([id], [name]) VALUES (" & myID & ",'" & myname & "')"
      currentdb.Execute strSQL
    I have guessed at the data types of your fields, so it may need some minor changes.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    Re: addnew record to recordset - performance issue

    There are like 30 fields in this table, and already implimented a recordset for updating the record... so implementing two separate functions (one for updating a record, and one for inserting a record) might be too complex to maintain later on.

    Any ideas on whats the fastest way to work with recordset?

    tHanks

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: addnew record to recordset - performance issue

    Updating is also much quicker with SQL - with an UPDATE rather than INSERT. For information on how to write one see the Tutorial in the "SQL" section of our Database Development FAQs/Tutorials (at the top of the Database Development forum).

    If speed is an issue, using a recordset is the wrong thing to do. Maintaining two strings (which is all that SQL statements are) isn't a big deal, and the rest of the code can almost certainly be shared.

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