axs221 wrote:
We use replication for our data, but our data is in a separate MDB
file. As for libraries, I do want to move some code into other
libraries, but with how my company has our code set up it isn't too
smooth of a transition.
Good, for a while there I thought you had been using replication to
distribute code changes. That was one of the original uses of
Replication, but it was so prone to problems that anyone in the know
about Replication now strongly recommends against it.
I've made a separate MDB file now for one module in our program, but
now the issue is trying to handle function calls that were in other
sections of the main database of the program, along with any queries or
the few globals that we use for keeping track of certain files and
things. Since the separate MDB can't refer back to the main program, I
created a third library for the calls that both databases need, but
this is kind of a hassle and might get messy. Is there a better way of
handling that?
I'm by no means an expert on Libraries, but I would think that if there
is something in the main program that the library function needs to know
about (variable, object, etc) that if you were to include it in the
parameters of the function call that would take care of things. This is
very similar to moving a function from a Form module, that has all sorts
of Me referrences, to a stand alone module (so it can work with more
than one form). For a simple function, I'll show what I mean with some
air code:
Code in Form:
Function ControlChanged() As Boolean
If Me!MyText.Value<>Me!MyText.OldValue Then
ControlChanged = True
Else
ControlChanged = False
End If
End Function
Code in Module:
Function ControlChanged(frm As Form) as Boolean
If frm!MyText.Value<>frm!MyText.OldValue Then
ControlChanged = True
Else
ControlChanged = False
End If
End Function
Or if you need to be able to refer to any control:
Function ControlChanged(ctr As Control) as Boolean
If ctr.Value<>ctr.OldValue Then
ControlChanged = True
Else
ControlChanged = False
End If
So, if you pass the appropriate Parameters, you should be able to make
the functions in the Library able to work even though they are isolated
from the main app. You mentioned Global Variables as well. If the
function only needs to refer to a few of them you can include them in
the parameters. There are a number of ways you could pass them all at
once if you needed to have the function be able to refer to any/all of
them. You could load them into an array ( GlobalArray(varName, varValue)
) and pass the array as a parameter. You could load them into a
Collection. Or for the ultimate in flexibility (and complexity too) you
could load them into a Class.
Obviously, the code that is the best candidate for a Library is code
that can easily stand alone with the minimum of parameters, but that
doesn't mean you can't deal with anything else. There will be a limit to
what you can practically move to the Library.
Hope that helped.
--
Bri