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

    Duplicating a Record

    Hi All,
    I am using VB5 Pro with Access 97 Database.
    I want to be able to Duplicate Part of the last record entered into the database.
    I have got this far but need help,

    Dim dbs As Database
    Dim fldTemp As Field
    Dim strSQL As String
    Dim rstMyRecords As Recordset

    Set dbs = OpenDatabase("c:\temp\duplicate\cars.mdb")
    set rstMyRecords = Form1.dtacars.Recordset

    rstMyRecords.MoveLast

    strSQL = "INSERT INTO Cars Values _('Vehicle','Manufacturer','Model'"
    For Each fldTemp in rstMyRecords
    strSQL = strSQL & "" & fldTemp.Value & ","
    Next fldTemp
    strSQL = Left(strSQL,Len(strSQL)-2)
    strSQL = strSQL & ")

    dbs.Execute. strSQL

    dbs.Close

    It goes into error at For Each and I am stumped.
    I only want to duplicate some of the text fields but there are numeric fields in the Recordset, so is this what is causing the problem.
    Please advise if you can help.
    Thanks
    [email protected]





  2. #2
    Join Date
    Aug 1999
    Location
    India-Delhi
    Posts
    106

    Re: Duplicating a Record

    Hi,
    There are some points before you duplicate the last record. If you are having index (unique) then table will always generate the error. So please ensure tha your table is not bound to 'unique' value field.

    Most probably you want to set your table behaviour as age old dbase "set Carry on"
    Ok. There is no problems in this, What I see in your code, you are missing a ")"
    2. If only three fields are to be inserted then use simply INSERT INTO tableName (... ... ...) Values(... ... ..) thats all.

    I hope you get it.

    santulan


    Santulan

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