Access Form suddenly stopped executing VBA code (solution) (Access365, Windows 10) - vba

This is not a question, actually it is how I fixed it.
I have an Access Form that is my start up and, of course, opens automatically. I have 1 button that runs VBA code, and suddenly, it stopped working, as well as the VBA code in OnFormLoad event. The buttons with MACRO code, though, worked fine.

Solution: I went to Design View, added a new button with the VBA code in OnClick event: msgbox "Works" (can be anything). Once clicked on the button, the code executed normally and, "magically", button and OnLoad script started working again. I have no reasonable explanation for that...

Related

How to step through VBA code behind a form? VBA error 2186: This property isn't available in Design view

I can run a macro under forms, but when I look at the code behind the form, I am not able to step through it all.
I hit the line
Dat = [Forms]![frmMenu]![dtmDate]
and get the error:
Is there a way to resolve this so I can continue to test each step of the macro?
I opened the code with ALT + F11.
I am trying to pinpoint the queries which cause the macro to take so long to run.
You can't hit f5 to run + debug code in a form. You can do this for a standard code module, but not for what we call a class module.
If you wish to debug/step code in a form? Launch the form (normal view). Then go to the code behind, say a button click, and now you can set a break-point.
So, single step, or debug of forms code requires you FIRST load the form as normal. (you can't thus use f5 to run such code). But, you CAN debug as per above.

MS Access: Repair broken button/control/vba

is there some way to repair broken functionality in ms access, like recompiling the thing?
I have a button on a form that is supposed to run vba code when clicked. The button no longer works, after like a couple of months. Except for the button getting focus nothing happens. I have tried the compact and repair option in access with no luck. The code works fine btw. I have made a new random button somewhere else on the form and literally copy pasted the vba code from the on_click event of the broken button to the new one, and on the new button it works perfectly. No problems at all. The old one, however, nothing. No matter what I do. I deleted the vba code in the on_click event, saved, closed and opened access again, then reentered the code. Still nothing. I tried removing certain functionality from the button by removing line by line, trying to see if any one line is the issue. Nothing again, no errors are being displayed, I don't think the button even runs the vba code at all.
In case someone wants to look at the code:
Private Sub Befehl107_Click()
[NavigationSubform].Form![stoffe_abfrage subform].Form.FilterOn = False
[NavigationSubform].Form![stoffe_abfrage subform].Form.Requery
Me.FilterAlleLink = "Alle"
Me.FocusDummy.SetFocus
End Sub
The button basically turns off the filter on a subform, requeries the form, sets the value for a textbox on the local form, and then gives focus to another textfield. Nothing complex really. I have 3 more buttons of the same type on my form that manage different filters for the same subform with almost identical code, they all work fine. Just this one broke.
Again, the code works fine if I make a new button, but on the old one it does not do anything.
Obviously I can just replace the button, but that would be annoying if down the line there is other functionality referencing it etc. So I was wondering if anybody encountered a similar problem and has a solution. Given that I have only worked with access for like 2 months total and already have this issue I hope there is some way to repair this more quickly, since I am now assuming that this will happen more frequently. Not sure though, maybe someone with more experience knows if this is common.
Edit: I just checked if literally copy pasting the broken button itself works and yes. I copy paste the broken button somewhere else, then copy paste the vba code from the broken button to the copy, and the copy now works...

Switching between workbooks in Excel VBA

For some reason Excel 2016 switches to a different workbook when I run a macro. There is no code that indicates this is happening.
I've tried to switch the focus back using
Appworkbook.Activate
but it only works if I put a breakpoint there. I've tried sleep as well. It works fine on Excel 2010 and the macro does what it is supposed to do.
Has anyone experienced similar?
*****SOLUTION (Not ideal!)*****
I ended up fixing this issue but adding a new button and calling the macro from a button_click method. I have no idea wy that worked and assigning the macro to the button didn't.
I ended up fixing this issue but adding a new button and calling the macro from a button_click method. I have no idea why that worked and assigning the macro to the button didn't.

Sheet-related processing causes Excel VBA Userform to stop processing Tab/Enter

This is a distilled form of a problem I'm having with a real application. Under certain circumstances, the initialization/activation code of a userform might result in the form losing its ability to correctly process tabs and enters: rather than switching between controls, these keys are passed to the controls themselves (even if they have TabKeyBehavior set to False). The simplest way I've found to systematically reproduce the problem is by having this at activation time:
Private Sub Userform_Activate()
Application.DisplayDocumentInformationPanel = True
End Sub
which seemingly causes Excel to "half-steal" the focus from the userform, so to say: the userform remains focused but tab/enter processing fails. The problem immediately goes away by switching to some external app and getting back to Excel (pressing ALT+TAB twice, for instance.)
Steps to reproduce the problem:
Download tabnotworking.xlsm.
Open tabnotworking.xslm.
Enable macros.
Click on the "Launch UserForm1" button.
UserForm1 is displayed and the textboxes accept input from the user, but tab/enter does not work as expected.
Press ALT+TAB twice or click on some external app and get back to the form: now tab processing works OK.
Once tab/enter processing has been restored, further usage of the form, including relaunching it, seems to work OK (most of the time). To reliably reproduce the problem again, close the book and start from step 2.
There are numerous references on the Internet to problems with tab processing seemingly related to this one, but no actual solution. Any clue on what's happening and how it could be solved? Thank you,

VBA Powerpoint Macro: Run in background

Can a macro run in the background whilst the user is using the presentation?
For example, some sort of auto-correct function or auto-format function>
This is very much possible. I have created a small demo to show how it can be done.
In this demo, I have placed a command button and whenever it is clicked (in presentation mode), it displays a message.
If I really needed to do something like this for some reason, I would probably add a form, put any code that needs to run concurrently in the form, have it run as part of the form's initialization subroutine, then from the main body of code, call the form modelessly.