L
LAS
In a different thread I was strongly advised not to do this: Set irst_StudentTracking = Me.RecordSet (in load event), and then use the recordset variable for subsequent sork.. I'd like to know what others think. Below are the pros and cons that I have been able to figure out. I'm using Access 2007. I'm interested in this because I certainly didn't invent the idea of Set <recordset variable> = Me.Recordset. I got it from an example somewhere.
Pros
- If you use a variable, you get a list of its properties and methods as soon as you type the dot at the end. This is not true with Me.Recordset. In fact, when you type your first letter, a tiny beep is emitted. It certainly feels like it's invalid. It's only because of the advice I got that I even tried to compile, say Me.Recordset.RecordCount.
Cons
- The reason given for not using a variable was that I would have two recordsets that behaved separately, e.g., "You are checking that the first recordset is on the new record but then trying to edit the second recordset which is not on a new record."
Since working with a variable has been satisfactory in a number of situations, I tested this idea by doing the following. I put the code before and after Me.requery, .AddNew and in the Current event. I put stop statements after all assignments below were made, and then issued the print command in the immediate window. I did not find any situation where the Me.Recordset values differed from variable's values. I did this when there were no rows and when there were one or more rows. Interestingly, .NewRecord seems to be a property of the form. irst_StudentTracking.NewRecord was not compilable for me. Although both Me.NewRecord and Me.Recordset.NewRecord were. Can someone give me a situation where the variable's properties and the form's recordset properties would diverge?
print lb_recordseteof, lb_recordsetbof,li_recordsetcount,lb_rsteof,lb_rstbof,li_rstrecordcount
Dim li_recordsetcount As Integer
Dim lb_recordsetBOF As Boolean
Dim lb_recordsetEOF As Boolean
Dim li_rstRecordCount As Integer
Dim lb_rstBOF As Boolean
Dim lb_rstEOF As Boolean
lb_recordsetEOF = Me.Recordset.EOF
lb_recordsetBOF = Me.Recordset.BOF
li_recordsetcount = Me.Recordset.RecordCount
lb_rstEOF = irst_StudentTracking.EOF
lb_rstBOF = irst_StudentTracking.BOF
li_rstRecordCount = irst_StudentTracking.RecordCount
Pros
- If you use a variable, you get a list of its properties and methods as soon as you type the dot at the end. This is not true with Me.Recordset. In fact, when you type your first letter, a tiny beep is emitted. It certainly feels like it's invalid. It's only because of the advice I got that I even tried to compile, say Me.Recordset.RecordCount.
Cons
- The reason given for not using a variable was that I would have two recordsets that behaved separately, e.g., "You are checking that the first recordset is on the new record but then trying to edit the second recordset which is not on a new record."
Since working with a variable has been satisfactory in a number of situations, I tested this idea by doing the following. I put the code before and after Me.requery, .AddNew and in the Current event. I put stop statements after all assignments below were made, and then issued the print command in the immediate window. I did not find any situation where the Me.Recordset values differed from variable's values. I did this when there were no rows and when there were one or more rows. Interestingly, .NewRecord seems to be a property of the form. irst_StudentTracking.NewRecord was not compilable for me. Although both Me.NewRecord and Me.Recordset.NewRecord were. Can someone give me a situation where the variable's properties and the form's recordset properties would diverge?
print lb_recordseteof, lb_recordsetbof,li_recordsetcount,lb_rsteof,lb_rstbof,li_rstrecordcount
Dim li_recordsetcount As Integer
Dim lb_recordsetBOF As Boolean
Dim lb_recordsetEOF As Boolean
Dim li_rstRecordCount As Integer
Dim lb_rstBOF As Boolean
Dim lb_rstEOF As Boolean
lb_recordsetEOF = Me.Recordset.EOF
lb_recordsetBOF = Me.Recordset.BOF
li_recordsetcount = Me.Recordset.RecordCount
lb_rstEOF = irst_StudentTracking.EOF
lb_rstBOF = irst_StudentTracking.BOF
li_rstRecordCount = irst_StudentTracking.RecordCount