How to share code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 

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

Back
Top