ON RECORD CHANGE

B

BlueWolverine

I would really like some on record change events off of which I could run code

how about
on record change
on previous record
on next record
on last record
on first record

just like the nav buttons at the bottom of a form.

IUt's really irritating to have to make custom nav buttons just so I can run
code off of them.
--
BlueWolverine
MSE - Mech. Eng.
Go BLUE!

----------------
This post is a suggestion for Microsoft, and Microsoft responds to the
suggestions with the most votes. To vote for this suggestion, click the "I
Agree" button in the message pane. If you do not see the button, follow this
link to open the suggestion in the Microsoft Web-based Newsreader and then
click "I Agree" in the message pane.

http://www.microsoft.com/office/com...54560e&dg=microsoft.public.access.formscoding
 
K

Klatuu

You want the form Current Event. It fires each time a record is changed. It
includes the first record and any time a new record is added.

As to your nav buttons. Have a look at this

Sub SetNavButtons(ByRef frmSomeForm As Form)

On Error GoTo SetNavButtons_Error

With frmSomeForm
If .Recordset.RecordCount <= 1 Or .CurrentRecord >
..Recordset.RecordCount Then
.cmdNextRec.Enabled = False
.cmdLastRec.Enabled = False
.cmdFirstRec.Enabled = False
.cmdPreviousRec.Enabled = False
ElseIf .CurrentRecord = 1 Then
.cmdNextRec.Enabled = True
.cmdLastRec.Enabled = True
.cmdNextRec.SetFocus
.cmdFirstRec.Enabled = False
.cmdPreviousRec.Enabled = False
ElseIf .CurrentRecord = .Recordset.RecordCount Then
.cmdFirstRec.Enabled = True
.cmdPreviousRec.Enabled = True
.cmdPreviousRec.SetFocus
.cmdNextRec.Enabled = False
.cmdLastRec.Enabled = False
Else
.cmdFirstRec.Enabled = True
.cmdPreviousRec.Enabled = True
.cmdNextRec.Enabled = True
.cmdLastRec.Enabled = True
End If
End With

SetNavButtons_Exit:

On Error Resume Next
Exit Sub

SetNavButtons_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure SetNavButtons of Module modFormOperations"
GoTo SetNavButtons_Exit

End Sub

Call it like this:

Private Sub Form_Current()
Call SetNavButtons(Me)
End Sub

Just put the sub in a standard module and use the same names for your nav
buttons on every form and it will work for all of them.
 
J

John W. Vinson

I would really like some on record change events off of which I could run code

how about
on record change
on previous record
on next record
on last record
on first record

just like the nav buttons at the bottom of a form.

IUt's really irritating to have to make custom nav buttons just so I can run
code off of them.

Ummm...

You can do all of this using the Current event.

You will need to keep track of which record is "previous", using the
Me.AbsolutePosition perhaps.
 
K

Klatuu

See my response, John. I have been using this for about 5 years now. It
works really well. I don't use AbsolutePosition, I compare CurrentRecord
against Recordset.RecordCount
 
J

John W. Vinson

See my response, John. I have been using this for about 5 years now. It
works really well. I don't use AbsolutePosition, I compare CurrentRecord
against Recordset.RecordCount

Thanks Dave... noted!
 

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