Why would an Access 2010 form button with an embedded "openreport" macro and a "where" filter, stop working until I add a new button? - vba

I decided to "tweak" an existing database to further manage multiple sources of income.
I copied the working database and created a "modification copy", just in case I messed things up horribly.
In the modified version, I have a button on a form (in fact, two different buttons with similar macro properties, just directed to do the same function to different reports.
The properties are your standard macro with an openreport, and a "where" condition.
Here's the problem. The macro has worked in the past, and continues to work on my "pre-modification" operating database.
On the modified database, after ensuring all the parameter elements are entered correctly, I can change the "view" to report view, and the macro seems to work just fine until I close the database.
As soon as I open the database, the buttons produce an error. See pic below.
The only way I seem to be able to resolve this odd button macro issue is by going into design view and adding a new button. I've discovered...I don't even need to embed a macro, just adding a new button seems to renew the macro operation...until I close and reopen the database. Then, I have to add a new button again to get the open database's macro to operate.
I can delete the new button added, and still have the macro buttons work, until I close and open the tweaked database.
I have zero VBA coding knowledge. I use Access's macro building tools and typically have to visit sites like this if I need to learn a new "trick" to get my database and it's various tools to do something.
I recently explored with the "subform" that can be seen above in the open form pic with the error message. My guess is that maybe that subform is somehow causing my macros to continuously fail???
Thanks for any help!

Related

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...

Forms not saving

Firstly, I apologise for my terminology and sometimes stupidity, as I am completely self/internet (mostly on here) taught. I've been developing an app for the past few years, mostly to help me with work, and more for kicks and giggles. I have now run into a problem that has me stumped! So I am calling out for any suggestions please :)
Okay, some background, I use colours on all forms to identify blocks of data based on an ID - it looks pretty, okay; and sometimes it's a quick identifier of which block the data belongs to when skimming through tables. So I have a form where I or the user can change these colours to whatever suits their eyes, needs etc. and there is a table that holds this information. Now these colours are applied using the 'Conditional Formatting' (when ID = 1 then background this colour, font that colour, etc). When a Form is opened in the FormLoad() code there is a check to see if the colours have been changed and if so then a module is called which updates all the 'Conditional Formats' on the Form (I should add here that it's only applied to the tables on the form), and everything looks pretty and more important works! Now this process is relatively slow (a couple of seconds on some forms), too slow to run every time the form is opened. So ages ago I found a way to force Access to save the design, including the 'Conditional Formatting':
DoCmd.RunCommand (acCmdDesignView)
Forms!PrePlanner!BtnHelp.Caption = "Help"
DoCmd.Save acForm, "PrePlanner"
DoCmd.Close acForm, "PrePlanner", acSaveYes
This works perfectly on some forms but not on other!!
At first I thought it was something to do with the subForms, as it WASN'T working on all the forms that have subForms and the ones it was working on had no subForms... So I copied one of a simple subForms (a recently created form) which can open as a normal form, made changes to the colours opened the TEST form, the colours updated as expected, closed the form with the above code and the Formatting WASN'T saved! :( (If I change the Help Button to say "Help!" this change IS saved)
The Forms that don't save with the above code are also the most recent Forms that I have designed, the ones that do save are older forms (a couple years old and designed on a different computer but the same version of Access). I copied one of these older Forms, changed the colours, etc etc and this it DID save!!!
I've been through and compared all the properties of a working form and a nonworking form and nothing, I've tried exporting and importing... Please any thoughts would really help my sanity!!
Thanks in advance
....I forgot to say that I'm using Access 2016 on a 64bit Windows 10 machine.
Additional Info.
Having played around this morning, I created a new form (from scratch) configured the records so that the Conditional Formatting can be applied, etc. Opened the new form the Conditional Formatting was updated, the form closed and saved. Upon reopening the new form everything was as it should be the Conditional Formatting was saved. So I then add a subForm, and tried again, the Conditional Formatting was updated, the from closed BUT this time without saving the Conditional Formatting!! I then removed the subForm and repeated the test, this time the Conditional Formatting was saved.
So it seems to be something to do with subForms, what changes to the form properties does adding a subForm trigger that would stop the Conditional Formatting from being saved? Is this a quirk in Access?
Thanks again.
Have you tried running your code to apply the formatting while the form is in design view? It seems like conditional formatting and properties don't save when updated via VBA while the form is in normal view mode. I've had good luck reopening the form in design, running the code, and then saving the form.

Search form doesn't work on front end database

I split a database and created a search form in the front end. It works there, but when I copy the front end, the search form doesn't work there
The form is a continuous form and has my table as a datasource. There are a number of bound fields in the detail section and a number of unbound fields in the form header. On the click of the search button, I use vba to build a sql select string and use Me.RecordSource = strSQL. Again this works in my original front end db. After realizing it doesn't work in a copy, I have tried copying and pasting the form from one front end to another, export/import, recreating it, hard coding a select, trying to display a message box on the click...nothing seems to work on the button click (tried double click too). If I build a button with the wizard, it will work, but they are using built in macros.
Any thoughts? Thank you in advance.
If no code seems to run in your new database (including MsgBox), then it is quite likely that the new database is in a folder that Access doesn't recognize as "trustworthy" and has therefore turned off code running.
Check that the folder where the database is currently located is allowed to run code, and if not add the folder:
File|Options|Trust Center|Trust Center Settings|Trusted Locations
Regards,

ActiveX controls changing to pictures (Excel/VBA)

My company creates workbooks for clients that contain ActiveX controls (in most cases we need the extra functionality as compared to Form Controls). When we create them, they work fine on our end, but when we zip them up and send them to our clients, they open the WB and the ActiveX controls are no longer ActiveX controls, if you right click it, it behaves like a picture.
I feel like this is due to the MS ActiveX debacle. I have had them run the Fix It and making sure all the MS Office components were closed, and had them reboot, but still nothing.
I am pulling out my hair, and have asked on other forums if anyone else has had this issue, and what they have done to fix it. Thanks in advance.
Could you please check in client system whether macros and active x controls are enabled in Trust center setting?
https://support.office.microsoft.com/en-us/article/Enable-or-disable-macros-in-Office-documents-7b4fdd2e-174f-47e2-9611-9efe4f860b12?CorrelationId=fe6a4d24-f4d9-4c6b-afa0-40d2828ad22e&ui=en-US&rs=en-US&ad=US
use above link if needed.
Try closing excel and deleting the .EXD files from your computer.
Source: http://www.mrexcel.com/forum/excel-questions/296750-command-button-turned-into-image.html
While saving the Excel document, save it as "Macro enabled workbook".xlsm
In my case, the worksheet prompts a non responsive error sometimes. When I reopen it, Excel repairs it and turns all active X check boxes (sometimes drop down list and command buttons) into images. It happened many times and I had to spend a lot of my time recreating them and liking to cells.
I experienced a similar problem when Excel repaired a file; this may be similar to what's happening with the Zipped file. FormControl Buttons don't appear to have the same problems but I see you want to keep the additional functionality of the ActiveX Control.
You may be able to make use of the code I created by inserting one Form Control button that runs the Sub RepairMissingButtons() that your clients can press to restore the images to CommandButtons. This currently fixes buttons for any selected sheets, so you'd want to first identify which sheets need to be selected (or add a form control button on each sheet that needs the repair done).
You'd need to modify the Sub CreateButton() to meet your needs (currently requires hard-coding the Caption, BackColor and any other ActiveX properties that may have been lost by the button being converted to an image):
Reverse Excel ActiveX command buttons erroneously converted to images after corrupted file repair
Having this problem, activex controls sometimes change to pictures.
Many places around the internet the answer is: Use form controls, well as far as I can tell form controls don't actually do anything useful.
Even Microsoft's support site says, recommend using form controls, how can that be the answer. being able to interact with VBA is as far as I can tell the only reason to use Microsoft applications instead of free ones.

How to update an Access VBA app with 30 forms?

I need to update an Access VBA app with around 30 forms in it.
I have to amend a screen that seems to have been set up right at the start of the app, it uses a lot of SQL tables. Is there an way of finding my way to the start of the code?
I come from a procedural coding background and I am unused to code that doesn't have a start and an end; I also know a bit of VB, some ASP, some .Net and general computing.
When something "automagically" happens upon opening an Access database, it is almost always because
A "startup form" has been specified. (In Access_2010 that's done in File > Options > Current Database > Display Form.) ...or...
The database has a Macro named AutoExec which is automatically run when the database is opened (unless you bypass it by holding the [Shift] key down while opening).
In addition to #Gord's answer, there's a few things you need to know. I'm going to give you the quick & dirty version.
First, there's 2 types of code in Access. VBA & macros. Sometimes what's called a macro, is really VBA.
In Access, a macro is a set of instructions to do something to the database. It's very limited in what it can do. These are often used by novices who don't know how to program in VBA.
VBA is the real powerhouse behind the scenes. It can do everything a macro can do, but a whole lot more.
Access uses an Event-Driven / Object-Oriented (at least close enough for this discussion) interface. Do a Google search on those meanings. But very quickly, the listbox on a form is an object. It has properties (like width), methods (add an item), and events (click on an item).
To see the code, for macros look to to your navigation window to your left. For VBA (modules), look to the same window, or just press Alt-F11. VBA can be used standalone in a module, or behind the scenes of a form or report.
Once you get the hang of it, you'll find Access to be a handy RAD tool for small projects.
Good luck.
It appears that you already have found the form that opens when the app starts (if not, check out Gord Thompson's answer).
The first things that happen when an Access Form opens (the "start of the code", as you called it) are the Load and Open events.
If there is any code in this form that is connected to these events, then it's in the Form_Load() and Form_Open() functions in the code of the form.