Good morning and Merry Christmas. I am attempting to perform an action at some point shortly at or after a form opens and I need to reference the opened/opening form (i.e., Screen.ActiveForm). I realize that the order of events for forms is:<\/p>\n
Open → Load → Resize → Activate → GotFocus (if no controls on the form) → Current<\/p>\n
I currently have a function that is called in the Current event; however, the function fails at the Screen.ActiveForm line. Is the form not active when the Current event fires?<\/p>","upvoteCount":5,"answerCount":9,"datePublished":"2023-12-25T14:58:38.000Z","author":{"@type":"Person","name":"donaldfisher3","url":"https://community.spiceworks.com/u/donaldfisher3"},"suggestedAnswer":[{"@type":"Answer","text":"
Good morning and Merry Christmas. I am attempting to perform an action at some point shortly at or after a form opens and I need to reference the opened/opening form (i.e., Screen.ActiveForm). I realize that the order of events for forms is:<\/p>\n
Open → Load → Resize → Activate → GotFocus (if no controls on the form) → Current<\/p>\n
I currently have a function that is called in the Current event; however, the function fails at the Screen.ActiveForm line. Is the form not active when the Current event fires?<\/p>","upvoteCount":5,"datePublished":"2023-12-25T14:58:38.000Z","url":"https://community.spiceworks.com/t/order-of-events-on-form-when-it-is-accessible-to-vba/964393/1","author":{"@type":"Person","name":"donaldfisher3","url":"https://community.spiceworks.com/u/donaldfisher3"}},{"@type":"Answer","text":"
I tested this and when opening form get error 2475 “You entered an expression that requires a form to be the active window.” - while this error message is open I can see there is not yet a form window in the app.<\/p>\n
I have never used Screen.ActiveForm and everything I’ve read advises against it. Why are you? Why not reference form by name or use Me alias?<\/p>","upvoteCount":0,"datePublished":"2023-12-25T18:00:41.000Z","url":"https://community.spiceworks.com/t/order-of-events-on-form-when-it-is-accessible-to-vba/964393/2","author":{"@type":"Person","name":"june7","url":"https://community.spiceworks.com/u/june7"}},{"@type":"Answer","text":"
Pretty sure you’re going to want to use the OnLoad property of the form to call your function. It will fire when the Load event completes.<\/p>","upvoteCount":0,"datePublished":"2023-12-26T11:55:01.000Z","url":"https://community.spiceworks.com/t/order-of-events-on-form-when-it-is-accessible-to-vba/964393/3","author":{"@type":"Person","name":"craigrrr","url":"https://community.spiceworks.com/u/craigrrr"}},{"@type":"Answer","text":"
@craigrrr<\/a> - I have attempted putting this into the Open, Load, Resize, Activate, and Current events with no success. It seems that none of the Form events that fire when a form is initially opened are fired when a form is the active form in Screen.ActiveForm. I am essentially trying to put the form name part into the function rather than providing it each time the function is called. I though that Screen.ActiveForm might be the answer, but have discovered otherwise.<\/p>","upvoteCount":0,"datePublished":"2023-12-26T14:14:23.000Z","url":"https://community.spiceworks.com/t/order-of-events-on-form-when-it-is-accessible-to-vba/964393/4","author":{"@type":"Person","name":"donaldfisher3","url":"https://community.spiceworks.com/u/donaldfisher3"}},{"@type":"Answer","text":" @june7<\/a> - I started out using Me.Name and passing the value to the function when called; however, I wanted to do the name-getting in the function rather than pass it every time. Apparently this is not possible.<\/p>","upvoteCount":0,"datePublished":"2023-12-26T14:16:30.000Z","url":"https://community.spiceworks.com/t/order-of-events-on-form-when-it-is-accessible-to-vba/964393/5","author":{"@type":"Person","name":"donaldfisher3","url":"https://community.spiceworks.com/u/donaldfisher3"}},{"@type":"Answer","text":" To reliably reference the active form, you might want to use the Activate event instead. The Activate event occurs when a form receives the focus, making it the active form. This would be a more suitable event if you need to perform actions when the form is opened and becomes the active form.<\/p>\n Private Sub Form_Activate() Private Sub YourFunction() By placing your code in the Activate event, you ensure that it runs when the form is opened and becomes the active form. Remember that if your form is opened as a subform, the Activate event of the main form will fire when the subform receives focus. Adjust the code according to your specific requirements and the structure of your application.<\/p>","upvoteCount":0,"datePublished":"2023-12-26T21:34:55.000Z","url":"https://community.spiceworks.com/t/order-of-events-on-form-when-it-is-accessible-to-vba/964393/6","author":{"@type":"Person","name":"spiceuser-f74cq","url":"https://community.spiceworks.com/u/spiceuser-f74cq"}},{"@type":"Answer","text":" @donaldfisher3<\/a> , NOT the Load event. The OnLoad PROPERTY of the form. Whatever you put in there will get called when the form is done loading.<\/p>","upvoteCount":0,"datePublished":"2023-12-27T11:42:26.000Z","url":"https://community.spiceworks.com/t/order-of-events-on-form-when-it-is-accessible-to-vba/964393/7","author":{"@type":"Person","name":"craigrrr","url":"https://community.spiceworks.com/u/craigrrr"}},{"@type":"Answer","text":" @craigrrr<\/a> - I do not see that those two things are different. The ‘On Load’ event is on the property sheet of the form. Is this not the ‘OnLoad PROPERTY’ that you are referring to?<\/p>","upvoteCount":0,"datePublished":"2023-12-27T18:41:40.000Z","url":"https://community.spiceworks.com/t/order-of-events-on-form-when-it-is-accessible-to-vba/964393/8","author":{"@type":"Person","name":"donaldfisher3","url":"https://community.spiceworks.com/u/donaldfisher3"}},{"@type":"Answer","text":" @spiceuser-f74cq<\/a> - Please see my reply to @craigrrr<\/a> :<\/p>\n
\n’ This event occurs when the form receives focus and becomes the active form.
\n’ You can perform your actions here.
\nYourFunction
\nEnd Sub<\/p>\n
\n’ Your code here, referencing the active form using Screen.ActiveForm
\nIf Not Screen.ActiveForm Is Nothing Then
\n’ Your code that references the active form
\nEnd If
\nEnd Sub<\/p>\n