Why MS Access pop up form doesn't regain focus after switching apps with Alt-Tab? - ms-access

I have an Access 2016 application that opens a pop-up form when user double-clicks on a record in a datasheet form. That's meant to be a 'detail form' showing all fields in record (datasheet shows only a few). Now, while editing data on popup form, I switch to another app (say Notepad) to copy some text from there or simply check some other thing. I then switch back to Access app by applying Alt-Tab. However, now focus is over datasheet form, instead of pop up form it was when I first switched to Notepad.
Can anyone please help on understanding why this happens? Ultimately I want to return focus over popup form whenever I switch back from any other app by using Alt-Tab, i.e., maybe by detecting in VBA when Access application gets focus back so I can set focus on desired form. I've read some suggestions about using some Windows API function but no detailed examples on that.
Any help will be greatly appreciated.

Related

VBA webcontrol automation problem with inputfield

I'm an accountant and I develop a lot of automation to carry the repetitive task of my job. I've been fairly successful with most of them, but I got stuck with some code I can't find the solution to and probably it's just a simple thing I should already know.
So it's like this, I used to use selenium and make the code open an IE instance and navigate, login, fill multiple fields, select radio buttons etc. But I was using this with sendkeys function and Tab.
Now I reviewed all the code and implemented a webbrowser element to a userform and I'm using HTMLdoc to interact with the webpage, the objective of the app is to open the website, fill the invoice information then send and save the file, right now I'm able to login and navigate to the new invoice page.
The problem starts here, I use this code to get the text to the input fields on the webpage:
HTMLDoc.getElementsByName("dataInicio").Item(0).Value = Controlo_Arrendamento.txt_dataInicio
HTMLDoc.getElementsByName("dataFim").Item(0).Value = Controlo_Arrendamento.txt_dataFim
HTMLDoc.getElementsByName("dataRecebimento").Item(0).Value = Controlo_Arrendamento.txt_novoData.Text
HTMLDoc.getElementsByName("valor").Item(0).Value = Controlo_Arrendamento.txt_novoPago.Text & ",00"
HTMLDoc.getElementsByClassName("btn btn-sm btn-success").Item(0).Click
What happends is, when the submit button was pressed, the website gives me an error in every field, then I realized that when the data is inputed on the website normaly it automaticaly updates other elements on the webpage, it goes through some validation, so when my code inserts the values on the textbox it doesn't trigger, only by typing the values in...
So, I tried to dig everywhere for a solution, I watched the HTML elements and what changes when the value is valid and it's checked, tried implementing a .checked = true but no solution.
Anyone knows what I can do to get trough this?
I could send you the webpage but it needs a login and since it's a nacional finances website I'm afraid I can't share with you any login, but I will leave here the website in question, it may help figuring out what type of form i'm interacting with.
https://www.portaldasfinancas.gov.pt
Thanks in advance

Macro not working without VBA Editor open

In one of my forms in my Access Database I have a button with a Macro Event that opens another form where two fields match. However, whenever I open my Database this button with the Macro Event doesn't work until I've opened the VBA Editor. After I've opened the VBA Editor and refreshed the form it works just fine.
Also, the Conditional Formatting that I've attached to one of my text boxes on this form (same form as button with Macro Event) doesn't work unless the VBA Editor is open either..
Any thoughts?
Just to clarify, after the VBA editor is closed the code works as well, it seems as if it just needs that initial opening. I have other VBA and Macro events that work without the VBA editor needing to be opened, like I said it’s just that conditional formatting and that specific macro event on my button. When I’m back at work on Monday I’ll provide more details when it comes to the code and etc.
Solved: So the code must have disabled, although there was no yellow bar indicating this was the case. I made a copy of my database to troubleshoot and when I opened the my new copy it asked me to enable code and now everything works fine.
Strange. I suggest you create an AUTOEXEC macro and run a function with something simple like just showing a message box in VBA. With that you can verify if your code is the problem or something else.

Prevent 'save design changes' for an open form when closing Access

I have a split form as my main interface in an Access 2010 application. As normal, users are able to resize the datasheet portion, reorder columns, etc.
However, I don't want them to save such changes when leaving the form. Each time the form is opened the default format should be loaded.
I've taken care of all but one closing method. To avoid them closing using the default close button I've set Border Style = None. Instead I have a Close Form button that uses DoCmd.CLOSE acForm, "Main_form", acSaveNo
But if the user clicks the close button for the Access application, it pops the 'Do you want to save changes to the design of form` dialog like always.
I looked into disabling the application's Close button, but messing with Windows API is beyond my skill (and there should be a way to accomplish this without going to extreme measures).
I found a way to do this. A combination of database options, form format options, and vba can do it.
Go to the 'Current Database' options screen in the main Access
options and uncheck 'Enable design changes in Datasheet view'. This will prevent all datasheet view design changes in the database, so you will have to go into design mode for any table changes. Users can still reorder and resize columns within a form, but Access no longer considers that a valid design change and will not prompt to save it no matter how you close the form
Set the form format property 'Save Splitter Bar Position' = No. The form will now clear any change to the bar location when the form is closed. Access got really weird on me about this setting, however. Once I had ever set the option to no, I could no longer use design view or layout view to set a new default bar position; it always reverted to the location where it was when I first tried this setting. Even resetting the option to Yes, saving the design change, and fully exiting the database did not fix this.
So I added an On Load event to reset the split form size when the form opens: Me.SplitFormSize = 9000. The numbers involved are surprisingly high; in the form properties list this is set in inches. Mine was 6.5", which apparently translates to 9000.
With these three changes (along with the steps I detailed in the question) Access no longer prompts to save design changes when the form is closed, even if the user is closing the Access application entirely. The form also snaps the split form bar back to where it should be on load.
Since the API is beyond my skill too, here is a left-field workaround.
Duplicate Main_Form and rename it "Main_Form_Template". Create an Autoexec module or edit an existing one and add:
DoCmd.DeleteObject acForm, "Main_Form"
DoCmd.CopyObject , "Main_Form", acForm, "Main_Form_Template"
That should reinstate the standard template for the user each time they open the database even if they were to save the form when closing Access.
Turn your close button off on the form.
On the form's property sheet, format tab, about 2/3 of way down. Set Close Button = No
This forces the user to close it via the button you created.

Hyperlink box (txtbox) on Access Form won't allow drop

I have a MS Access form that is bound to a query in the database. I added a textbox and added a row source to a Hyperlink datafield in the query. When I open the form, it won't allow me to drop a file into the textbox.
Here's the deal. When I follow this EXACT same process on a new form, it works perfectly. That is, I open a blank form and I bind the form to some new query, let's say qryNewIdeas. Then on the blank form i add a textbox, let's say Text0. Then, when I select Text0, I go to the data tab - row source and choose the dropdown arrow to select the hyperlink field, lets say NewIdeasAddress. I click SAVE and open the form. It works PERFECTLY.
BUT, when I repeat this on an existing form (the one where I need the thing to actually work), it does nothing. It adds and changes the textbox to a hyperlink box (I note this because of the blue underlined word that appears in the box). But it won't allow me to drop files to this location.
I tried commenting out ALL of my VBA code to try to make sure that something wasn't hindering it (say in an OnLoad event) AND I've checked all of the form and control box properties and they seem to be the same in both the existing form and the test form.
I can't determine why it works on one form and not the other; Solution needed.
If you have access to "the data tab - row source ..", you are in design view.
When you later open the form, you are in form view, a completely different animal which specifically prohibits design changes.
It sounds like you will have to rethink your concept.

Forms calling reports in access

Step1: I open an Access form when the software opens. It acts like a switchboard manager where the user can open other forms and reports. (Popup = yes, modal = no)
Step2: Click to open a "Master Form" which also has other options. (ditto) So the original VB code called this form to be open and is still "running" in the background.
Step 3: Click to open a report based on the record selected.
So now there's 2 forms open and 1 report. User cannot toggle between them, must close one to get to the other (necessary).
On the open report, I would like to modify the rightclick commandbar. However, "Close" doesn't work because Access now shows Form1 and Form2 above as gray and Access is locked. I would like to be able to right-click to do a number of things including Close, Change to Design View, etc. But if I'm locked out like this, none of these will work.
I searched on...
1. Ending the background vba that's running - no luck
2. Setting focus on the active screen name - no luck
3. Setting focus on a control on the Form2 above - no luck
4. Tried all kinds of CommandBar things, no luck (ID choice vs. manual OnAction) and many more
I'd be happy to attach what I'm doing but it's pretty big, although I could probably cut out the sections that this applies too...
I've been searching for about 16 hours now... Anyone???
Thanks so much.
Popup = Yes in Access means two things:
The form or report stays above all other forms and reports that have Popup = No and above Access’ application window.
The form or report is not bound to the area of Access' application window and can be drawn outside of it.
You have two options:
Set Popup = No for the two forms. In this case they will be tied to the application window area.
Set Popup = Yes for the report as well, so that it can stand in front of the two forms.