Is Form_Load in Access 2007 generic? - ms-access-2007

Having a basic problem with Form_Load. I have some code for that procedure. I have it generated for a particular form, but it seems to open on the other form I have in the app as well. Is there just one Form_load procedure that gets executed for all forms or did I miss something? If not, then I understand somehow I will have to put code to only do certain things for certain forms.
Thanks in advance.

No. There is a Form_Load event handling method for each Form.
You have very likely wired up the same Procedure to 2 forms.
[Please show code for a more definitive answer.]

Related

How do I get to a control in a subform

I want to go to a control in a subform in order to be able to enter data.
I can make a DoCmd.OpenForm but then I get an extra copy of the subform on top of the main form. I would rather go directly to the subform. I have tried a lot of options and the following I thought was the most promising
Me.Subform.SetFocus
Me.Subform.Form.mycotrol.SetFocus
DoCmd.GoToControl "mycontrol"
This piece of code does not stop at the Subform to let me enter data. I have also tried Me!Subform with the same result. I have thought of adding a Stop statement, but then I don't know how to resume execution when data has been entered to the subform.
I think there is something I have not understood. Can someone help me out?
Biørn Veirø
VBA is single threaded. It can't work with Access forms this way. You could do it with a modal popup that returns a value, like an InputBox. Access forms don't return a value this way.
If you really want to have a step by step using Access forms then you need to hook in to form events. For this specific case I think the event you want is TextBox.AfterUpdate
https://learn.microsoft.com/en-us/office/vba/api/access.textbox.afterupdate-event
You can have different events on each control object, allowing you to have code that runs after each input.
First set focus to the subform control, then the control in the form:
Me!YourSubformControlName.SetFocus
Me!YourSubformControlName.Form!YourControl.SetFocus

How to call an afterupdate event from another module/control event (MS ACCESS VBA)

I have been using Microsoft access for a while however i seem to be having some difficulty with a single line of code. i know it is possible to trigger a form controls event from another module or event as i have done before in VBA for excel, however when i try to do this in MS Access it gives me a runtime error
any and all help would be appreciated in this matter as I'm sure there is probably something very basic that I'm missing here.
Please see below code for easy reference.
Forms("Insert_Data_Others").CMBVoy_ID_Oths.AfterUpdate
Call CMBVoy_ID_Oths_AfterUpdate
Make sure procedure is not declared as Private.
Use underscore in place of the last period.
Forms("Insert_Data_Others").CMBVoy_ID_Oths_AfterUpdate
or this version which will show the event in intellisense tips.
Form_Insert_Data_Others.CMBVoy_ID_Oths_AfterUpdate

Hide modeless form when all macros stop

First of all I want to thank everyone who has helped me with answers here. You guys have been important in my development and for that you have my respect.
For the question: I want to create a form that displays the status for running multiple macros in sequence. For that i'm showing a form modelees so the macros continue running in the background.
The way I have it setup now, the form remains visible after macros are done.
Is there a way i can trigger the form to hide/unload when no macro is running?
Thanks,
Daniel
Just unload the form at the end of the last macro. I assume you have one calling sub which handles showing the form and calling the macros, so that is where I would also hide the progress form.

MS access event load form

I have about 20 MS-Access databases with about 400 Forms and wish to perform an action whenever any form is loaded.
I would need, perhaps, an event at database or application level that would trigger at any form being opened/loaded. Then I might need only to add code once to each of the 20 databases, but not to each of the 400 forms.
And: it has to be in VBA (Access >= 2010)!
My Question: Is this even possible? And if so, does someone have a hint?
Thanks,
Pete
There are multiple ways to go about this, I think.
What I'd probably do is the following:
Create a hidden form that opens whenever your database opens (using an autoexec macro) with a timer.
When loading the hidden form, initialize a collection/multi-level array of all available forms in the database, and set their status to closed (somewhat difficult, probably would go with multilevel array or a collection inside a collection to be able to store form name + boolean open or closed).
Periodically iterate the collection, check for changes, so you can see whenever a form closes and trigger your event.
You could also use VBA to iterate through all the forms, add a module to them if there is none, and then add your desired Form_Load code to that module. (Would probably be wise to simultaneously create code to undo that action, so you can actually maintain the code). While refining that, you could check if the form already has a Form_Load action, and append code to that if it exists.
Alltogether, possible, but difficult. If you want pointers on some of the steps, I can give them, but for major issues on the implementation, I'd ask a separate question.

How to call multiple subs with a BackgroundWorker

I have not yet used BackgroundWorker but believe I need to use these in my code.
My app does a lot of database work, running many SQL queries in sequence. My problem appears typical, that the main form becomes unresponsive.
I want to be able to display progress using a progressbar and a toolstripstatuslabel. I am doing this already, but without the BackgroundWorker.
My code is - unsurprisingly - divided into a several subs, which are called in sequence by the main form.
All the examples I have seen include just simple BackgroundWorker DoWork events. What is the correct way to deal with calling other code? Just call the modules as usual in the DoWork event? I do understand these must contain no user interface code.
Am using VB.Net 2010
Thanks!