Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2006

    Unanswered: Access 97 is adding the new record to top and bottom of table.

    Good evening,
    Im trying to do a simple add new record to a table from text boxes on a form. When I run the code is adds some of the fields into the first record and adds it fully into the last record.

    Here is my code:
    Private Sub cmdAdd_Click()

    Dim dbsFish As Database
    Dim rstProd As Recordset
    Dim strProdID As Long
    Dim strCatID As Long
    Dim strCode As String
    Dim strDescription As String
    Dim strPieces As Long
    Dim strRemarks As String

    Set dbsFish = CurrentDb()
    Set rstProd = dbsFish.OpenRecordset("tblProduct", dbOpenDynaset)

    ' Get data from the form.
    strCatID = Me.CatID
    strCode = Me.Code
    strDescription = Me.Description
    strPieces = Me.Pieces
    strRemarks = Me.Remarks

    'Run function with entered data
    AddName rstProd, strCatID, strCode, strDescription, strPieces, strRemarks

    'Close records after new entry

    End Sub

    Function AddName(rstTemp As Recordset, strCatID As Long, strCode As String, _
    strDescription As String, strPieces As Long, strRemarks As String)

    ' Adds a new record to a Recordset using the data passed
    ' by the calling procedure. The new record is then made
    ' the current record.
    With rstTemp
    !CatID = strCatID
    !Code = strCode
    !Description = strDescription
    !Pieces = strPieces
    !Remarks = strRemarks
    .Bookmark = .LastModified
    End With

    End Function

    I can get around it by using a macro to open the table and manually entering the data but this gives the user access to the table and I don't want them messing with that!.

    All help appreciated.
    T (My Access 97 Bible is on the way from America - but the mail system takes forever.!)


  2. #2
    Join Date
    May 2005
    Nevada, USA
    Provided Answers: 6
    It sounds like the form is bound to the table, and displaying the first record at the point you begin this process. If so, the data entered at that point is actually editing the first record. The process you're going through would be more appropriate for an unbound form.

  3. #3
    Join Date
    Jun 2006

    Access 97 is adding the new record to top and bottom of table.

    Thanks Paul. That was the problem. Lucky I have a crew cut otherwise I would have pulled out all my hair trying to solve it.


Posting Permissions

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