Why clone an MS-Access recordset?

后端 未结 4 1629
孤独总比滥情好
孤独总比滥情好 2020-12-20 18:51

I\'m a newbie at VBA and attempting to understand someone else\'s code.

Set rstClone = Me.RecordsetClone
rstClone.MoveFirst

<
4条回答
  •  清歌不尽
    2020-12-20 19:39

    Keep in mind that record sets have which called a clone method. This is different then the forms record set clone.

    In your example and question we talking about the underlying data that the form is based on.

    If you’re going to play with, and move through records using code that that a form is based on, but you don’t want the form display or graphical interface to follow you along or jump around then your example is the correct and preferred way to accomplish this.

    So, record set clone is a copy of the forms data. It allows you to move or traverse records in that record set, but the form (the user interface) does not follow your moving through the records.

    Remember, in some cases if you do in fact want the form to move to the next record, then you would not use records set clone, but Use the actual record set.

    Eg:

    Set rstClone  = me.recordset
    rstClone.movenext
    

    In the above, the form would then move to the next record.

    A typical situation is when you’re using sub forms. If you wanted to total up or traverse the 10 records in that sub-form, you can do so without affecting or causing the current display record the sub form is currently pointing to change. It lets you do things Behind the scenes so to speak.

    However, if you just wanted to move to the forms next record, then you don’t need either reocrdset, or recordset clone, you could just execute a command that moves the form to the next record.

    You could use the following typical command :

    DoCmd.GoToRecord acActiveDataObject, , acNext
    

    And, you don't need recordset, or recordsetClone if you wanting to look at values in code placed in a form, you can just go:

    me!nameOfCollumFromTable
    

提交回复
热议问题