How to share code

R

Rod

Let's say I have the following:

Private Sub btnRefRes_Click()
Me.Remaining_Calls = Format(Nz(DCount("*", "tblCandidates", "[Source] =
0 "), 0), 0)
End Sub

But this code is needed in many forms in the same db. What would the code
look like so it is accessible by other forms in the db using same block of
code so I do not have to duplicate the code many times?

Thanks.
 
D

Douglas J. Steele

Create a public function in a module (not associated with a form)

Function RemainingCalls() As Integer

RemainingCalls = Nz(DCount("*", "tblCandidates", "[Source] = 0 "), 0)

End Function

Change how you get the value to:

Private Sub btnRefRes_Click()
Me.Remaining_Calls = RemainingCalls()
End Sub
 
Top