Access vs Vbasic

  • Thread starter Thread starter KK
  • Start date Start date
K

KK

Hello,

I have a database that I've been planning to open & manipulate using Visual
Basic, but I wonder if I actually need to use Vbasic at all. I might be able
to do what I want in Access directly.

I know how to design a form and move back & forth through the database one
record at a time, but can I put command buttons on the form and program them
to move back / forwards by a preset number of records?

Thanks

KK
 
I know how to design a form and move back & forth through the database one
record at a time, but can I put command buttons on the form and program them
to move back / forwards by a preset number of records?

Certainly. A Form has a RecordsetClone property which you can use; the
Recordset object has a Move method, and a Bookmark property. Just Move
to the desired record (trapping errors for when you hit end of file)
and then set the Form's Bookmark property to the recordset's Bookmark
to synchronize.

John W. Vinson[MVP]
 
Hi KK,

It's probably easier to do this in Access than in Visual Basic (almost
all database work is). Just put a couple of buttons on your form and in
their Click event procedures put something like
DoCmd.GoToRecord acActiveDataObject, , acNext, 5
to advance 5 records, or
DoCmd.GoToRecord acActiveDataObject, , acPrevious, 5
to go back 5.

You may want to include error trapping to handle what happens if a
button is clicked when there aren't enough records to allow the move you
want, something like this air code:

Private Sub cmdMove5Records_Click()
On Error Goto ErrHandler:
DoCmd.GoToRecord acActiveDataObject, , acNext, 5
Exit Sub

ErrHandler:
Select Case Err.Number
Case 2105 'Can't go to specified record
DoCmd.GotoRecord acActiveDataObject, , acLast
Case Else
Err.Raise Err.Number, Err.Source, _
Err.Description, Err.HelpFile, Err.HelpContext
End Select
End Sub
 
Back
Top