I'm hoping someone can explain, or tell me where to find a good explanation, on getting things working between vba modules. That is, to make public variables that have a single instance across multiple modules and to make public functions that are visible from any module even if that module is connected to a subform. I'll explain what's going on with my code to make clear what my issues are.
I have a module for a form, [Form_Song List subform]. This is used to enter song information and uses various event calls. The event calls then call other functions I've written, some of which I want to call from modules outside of [Form_Song List subform]. So I thought I'd put non-event-call functions into their own module, which I called [SongAddingRoutines].
Today I realized there was an issue. in [Form_Song List subform] I declare a variable: "Public action_taken as Integer". This tracks the last action I've taken regarding adding songs. After an issue arose, some debugging indicated that if I put action_taken in a watchlist from [Form_Song List subform] and from [SongAddingRoutines], Access sees these two separate variables which can have different values at the same time.
So I took all the code from [SongAddingRoutines] and put it back in [Form_Song List subform]. This fixed the issue I'd been having. However, when another module tried to call one of the functions that had been moved, it couldn't see it even though it's declared "Public Sub AttachRecordingtoDisc(Recording_id As Long, Optional LP_id As Long = 0)". So I wound up having to simple copy and paste two functions from [Form_Song List subform] directly into that other module.
So, is there a way to declare a variable that will be the same over multiple modules? Is there any way to make a function in a subform-specific module visible to all modules?
The ultimate goal is simply to have better organized, non-repeated code, so any advice on that is appreciated.