Building a Maintenance log book in access. Had to redo a data entry form so I started over with a new form in a new database then copied some working code from the old form to the new. In doing so I changed the names of a couple of combo boxes in the new form in order to keep things consistent. Problem is, the code I copied has the old name of some of the combo boxes and I can't change those names to the new names. The new names don't present when using autofill, just the old ones. Is there a way to correct that.(Easy, I Hope)
Example: in the old form the name of a combo box was actionCB. In the new form the box is named ActionCB, but now any code I write uses the old name.
This might be happening because you have compilation errors. Try compiling the application and fixing any errors. Or possibly this could happen if you happened to be stepping through the code at the same time (but I doubt it from your description)? Also VBA is beautiful in the fact that almost always you can make code changes while stepping through the code... but I've experienced the changes not saving from time to time.
MODIFIED FOR NEW QUESTION
As to your second question below in the comments. You can view and select a Form or Reports controls by using the Forms Property Sheet. If you look at the combobox at the very top of the property sheet it lists all Form or Report controls. You can select these objects by simply selecting them from the combobox.
Access is not case sensitive
"Example: in the old form the name of a combo box was actionCB. In the
new form the box is named ActionCB, but now any code I write uses the
old name."
If you're code is not updating to reflect the "ActionCB" name automatically, then you're probably trying to reference it where it's not available. This isn't going to generate an error if you don't have Option Explicit statement at the top of your module.
It'll just assume you know what you're doing and assign it to a Variant data type.
Put Option Explicit at the top of all your modules, and the debug | compile untill all errors are fixed.
Related
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!
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.
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,
Edited / re-written due to jmcilhinney's comment...
I have a project which uses several DGVs bound to an Access db. The form designer show 3 data sets for some reason, even though the solution explorer shows only one and all the tables are shown in that one data set's designer.
I can edit the first DGV but not another on the same form, the first is filled with the following...
Me.PingMonitorPLC_IPsTableAdapter.Fill (Me.PingMonitorDataSet.PingMonitorPLC_IPs)
And the other is filled with the following code...
Me.ActiveAlarmsTableAdapter.Fill(Me.PingMonitorDataSet1.ActiveAlarms)
jmcilhinney's comment is that I must be doing something wrong, the form load event only runs the code listed above.
I dont know why I have 3 data sets listed on the form designer and I am too scared to go deleting things as I have lost an entire project before because I corrupted the designer by deleting controls etc.
I'm sure this is a simple question, with a simple answer, but I can't find it.
I've inherited a spreadsheet that I have to fix. Whoever wrote it made extensive use of VBA and VBA UserForms for inputting data. On one form, textual and numeric information is entered and then saved to a record on a specific worksheet. This spreadsheet is used to log project information. It gets copied, and re-copied again and again. With each re-copy, it is cleared and used for the next project.
A user has sent me a spreadsheet of one of these major projects. The VBA, data-entry UserForm has a problem. One TextBox, which accepts either text or numbers, is always reformatting the numbers as dates when you exit the field!? I've tripled-checked the VBA code. There is no special OnEnter or OnExit code related to this field that reformats the data. Furthermore, I can't find a Format property that is associated with the TextBox from within the designer.
I'm a C/C# developer, not a VBA developer. Still, this "simple" IDE has me stumped. I can't find the property that re-formats the TextBox display value.
How can I fix the TextBox so that it persistently interprets numbers as numbers and not as dates?
FURTHER NOTE
It is worth mentioning two things. First, user's can't modify these forms or VBA code. The underlying modules are password protected and only myself and a couple managers know the password. Furthermore, no one touches the code because I'm the only developer within the company and everyone is a bit scare that they might break something.
Second, something in the file may have been corrupt. When this file was sent to me, the user also mentioned that the worksheet that he was working on was renamed. It appears that something didn't save properly because the WorkSheet tab was renamed a random hex string value.
Everything appears to be functioning as normal on this form, other than these two issues. Any help or guidance would be greatly appreciated.
You can force the proper format by using cLng:
First enter =TODAY() in cell A1 and then run:
Sub TextBoxIssue()
With ActiveSheet.Shapes("TextBox 1").TextFrame.Characters
.Text = Range("A1").Value
End With
MsgBox "However when we use cLng......"
With ActiveSheet.Shapes("TextBox 1").TextFrame.Characters
.Text = CLng(Range("A1").Value)
End With
End Sub
There is most certainly code that is formatting that text on exiting the textbox. You just haven't found it yet. If you go into the Userforms class module and select the textbox from the left dropdown, you can see all of the events in the right dropdown. The bolded events are in use. I assume you've already checked all those, but that's the place to start.
Next, look for custom class modules that use the WithEvents keyword. They can trigger events outside of the userform's class module.
Finally, search the code for all instances of =Format(tbxName.Text,"mm/dd/yyy") or some such code. Somewhere the code is probably using the Format function to fill that textbox.