• Properly reading the recordset

    Author
    Topic
    #493316

    My scenario:
    1. Items for a job are kept in an items table and are shown in a subform when the job form is opened.
    2. When a delivery docket is formed rows from the the items table tblItems are copied to the delivery docket items table tblItemsDD. This way the text can be edited for the delivery docket with changes being made to the original items.
    3. Items cannot be added to the delivery docket after creation and of course, this is what they want to be able to do. 😡

    This what I am trying:

    On the job form I have added this code to the subform enter event:

    Code:
    reccount = sbfItems.Form.Recordset.RecordCount

    To the subform exit event I added:

    Code:
    If sbfItems.Form.Recordset.RecordCount > reccount And [DelDocked] Then…..

    and it works. In that it only triggers if an item has been added to the list and the job is already flagged as being docketed.

    So I have my trigger event working ok.

    What I want to do now is read the values from the last (new) record and paste them into a new record in tblItemsDD

    I want to do it this way rather than reading from the last file in tblItems as I cannot guarantee it will always be the last item – multi-users

    But it dies in the position shown below

    Code:
    If sbfItems.Form.Recordset.RecordCount > reccount And [DelDocked] Then
    docket = [DDocket]   [COLOR=”#FFA07A”]’read from form[/COLOR]
    jobn = [Job #]         [COLOR=”#FFA07A”] ‘read from form[/COLOR]
    Dim rst As DAO.Recordset
    Set rst = sbfItems.Form.RecordsetClone
    rst.MoveLast
    iid = !ItemID        [COLOR=”#0000FF”]<<<<<<<<<<<<<<<<<<<[/COLOR] it dies here with [COLOR="#DAA520"]Compile Error: Invalid or unqualified reference[/COLOR] with [B]!ItemID[/B] highlighted
    iqty = !ItemQty
    idesc = !ItemDesc
    itcost = !ItemCost
    rst.Close
    Set rst = Nothing
    
    Set rst = CurrentDb.OpenRecordset("tblItemsDD")
                With rst
                .AddNew
                !ItemID = iid
                !DocketNum = docket
                !JobNum = jobn
                !ItemQty = iqty
                !ItemDesc = idesc
                !ItemCost = itcost
                .Update
                End With
    rst.Close
    Set rst = Nothing
    End if

    I can count the records but not read one what am I doing wrong?

    Viewing 0 reply threads
    Author
    Replies
    • #1438292

      I worked it out!

      Set rst = sbfItems.Form.RecordsetClone needed to be Set rst = me.sbfItems.Form.RecordsetClone

      and I also needed to define my variables

    Viewing 0 reply threads
    Reply To: Properly reading the recordset

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: