Making Event Procedures available to any Event in Access

A

Andy Cap

Hi,
I have a number of procedures that are called by various form field events
but it would be very handy to have certain procedures available within a
complete form or from within multiple forms within a database.

Thanks for any help you can offer.
Andy :)
 
K

Klatuu

If you have generic routines you would like to be available to all forms, put
the code in a standard module and change the declaration from Private to
Public. Then in the event for the forms, call the procedure. Here is an
example from a module in my application named modFormOperations. I call if
from the form Current event

Call SetNavButtons(Me)

Sub SetNavButtons(ByRef frmSomeForm As Form)

On Error GoTo SetNavButtons_Error

With frmSomeForm
If .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
 
A

Andy Cap

Thank you very much!

Regards,
Andy

Klatuu said:
If you have generic routines you would like to be available to all forms, put
the code in a standard module and change the declaration from Private to
Public. Then in the event for the forms, call the procedure. Here is an
example from a module in my application named modFormOperations. I call if
from the form Current event

Call SetNavButtons(Me)

Sub SetNavButtons(ByRef frmSomeForm As Form)

On Error GoTo SetNavButtons_Error

With frmSomeForm
If .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
 
T

Tim Ferguson

I have a number of procedures that are called by various form field
events

If you declare them in a standard module as

Public Function MyFunction()
' nb no return type
' ...
End Function

then you can use them directly in the controls OnXxx event property

=MyFunction


Note that a Sub will not work.


Hope that helps


Tim F
 
A

Andy Cap

Thank you very much!

Regards,
Andy


Tim Ferguson said:
If you declare them in a standard module as

Public Function MyFunction()
' nb no return type
' ...
End Function

then you can use them directly in the controls OnXxx event property

=MyFunction


Note that a Sub will not work.


Hope that helps


Tim F
 

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