Move around records in a form (1 Viewer)

FuzMic

DataBase Tinker
Local time
Today, 15:49
Joined
Sep 13, 2006
Messages
719
Hi members

For years i have been at odds to determine the best way using VBA to move around records at an opened form.

To begin, i have problem to identify the current record position form VBA. Actions such as FormName.requery will move it to the first record thus needs handling. To identify the original position of the form, i use the content in a FieldName eg Old$ and then find it as follows:

FormName.FieldName.SetFocus
DoCmd.FindRecord Old$

I feel this is not the best option. I think if we know the original position eg 7 at the form and we can use the following code

DoCmd.GoToRecord acDataForm, "FormName", acGoTo, 7

Q: Is there another smarter way?
Q: How to determine the original position of the form?
Q: In paradox.dos if we are the last or first record, we can determine it by referring its properties eg LastRecord. How do we do this in VBA?

Appreciate advice.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 17:49
Joined
Jan 20, 2009
Messages
12,852
The record number of the current record is returned with the form's CurrentRecord Property
The GoToRecord Method has acFirst and acLast.
 

missinglinq

AWF VIP
Local time
Today, 03:49
Joined
Jun 20, 2003
Messages
6,423
To set a "bookmark" if you will (an actual bookmark isn't accurate if records are d/c'd or added) requery then go back to the same record

Where [UniqueField] is a field unique to only one record.

Where [UniqueField] is Text
Code:
Dim UF_Rec as String
   
   UF_Rec = Me!UniqueField
   Me.Requery
   Me.Recordset.FindFirst "[UniqueField] = '" & UF_Rec & "'"

Where [UniqueField]is Numeric
Code:
Dim UF_Rec as (Fill in number type here)
   
   UF_Rec = Me!UniqueField
   Me.Requery
   Me.Recordset.FindFirst "[UniqueField] = " & UF_Rec
Linq ;0)>
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 17:49
Joined
Jan 20, 2009
Messages
12,852
Linq's technique is kind of similar to what FuzMic was doing with the FindRecord.

However it has a huge advantage in that it can define the field to search. The FindRecord goes through all fields so firstly it is slower but more importantly it can hit another field that happens to have that value too.

With true Bookmarks my understanding is the they are not only perturbed by the addition and deletion of records after a Requery but by the act of Requerying itself. They are suposed to be valid only for the recordset they were created on and technically a Requery is a new recordset.
 

FuzMic

DataBase Tinker
Local time
Today, 15:49
Joined
Sep 13, 2006
Messages
719
Much appreciate the views from both of you; ample to tackle this from another perspective. Sometimes a little pointer here and there, propels a big leap forward. Thanks again, mates.
 

Users who are viewing this thread

Top Bottom