Access 2000: Selecting records programmatically

M

Mike Mertes

Hi all! :)

What objects and methods are used to manipulate the record selectors on a
form? For instance, how do I switch to the last record? Or switch to a new
record?

Also, what steps should I take to run code when the an *.mdb closes? I've
noticed that there are no Auto_Open/Auto_Close events. I am aware of the
AutoExec macro, does it have an opposite?

Thanks for helping us Access newbies :)

-Mike Mertes
Airtron, Tamp Bay
 
A

Allen Browne

Use the RecordsetClone to find and move to records in the form.

Example: move to last record:
With Me.RecordsetClone
.MoveLast
Me.Boomkark = .Bookmark
End With

Example: move to a particular record:
With Me.RecordsetClone
.FindFirst "ClientID = 99"
If .NoMatch Then
Msgbox "Not found"
Else
Me.Bookmark = .Bookmark
End If
End With

To move to a new record, the form must have focus:
If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
End If

In each of those cases, the current record must be saved before the move can
happen, and you can avoid some problems if you do that explicitly:
If Me.Dirty Then
Me.Dirty = False
End If

To simulate an application close event, open a hidden form, and use its
Unload event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top