How to have an auto filled field save into table? - vba

i've had a look around for an answer to this but couldn't find a definitive answer (if some can point me at a thread that does answer this i'd appreciate it).
I've created basic database where queries are logged and then reported on. When someone logs a new query it goes into a table called "TBL Main Log", this is done on a basic data entry form and when they select "Country" a field called "Owner" is auto populated. However, when i click save at the bottom, this data doesn't get pulled through into "TBL Main Log". My save is run off a basic close window and save macro.
I have set up my autofill being fed off a combo box for "Country". I'm assuming i need to do something in the event properties after update. I'm pretty limited with my coding abilities so could answers be dumbed down as much as possible for me.
Cheers
Luke

Based on the comments:
me.Refresh on forms forces bound controls to save to the table.

Related

Can Access ensure a new form record displays all fields?

I have a database where I don't want some fields showing depending on data in other fields. I'm still new to VBA, having learnt how to do things I need via the internet (there's not much call for it in my job so like to try it out on side projects) for the things I need and have managed to create some code that hides certain fields that aren't needed, depending on what's been entered in another field and that works okay, if not perfectly (I'd like it to only work on the current record and not all of them at once but will worry about that later). My problem is, if I'm entering information onto a record and any of those fields become invisible exactly as I would want them to, then if I have more records to complete and load a new record, those hidden fields are also hidden on the blank record before any data has been entered and I want each new record to show all fields from the outset.
Another thing I've noticed is that if I close the database, next time I go into it the hidden fields have unhidden themselves again so I know I'm missing something important.
Here's a screenshot of a bit of the code where I want 2 other fields (What_reason and Date_sent_to_new_owning_School) to be visible depending on whether the answer in the current field after update is "Standard" or "Non-standard":
I'm sorry if this is really entry-level stuff but I AM entry level and trying to learn. This bit does work, albeit not perfectly as I'd like it to only work on the record I'm in at the time, and not go through and hide that field in all the other records at once (which it's doing).
I've searched everywhere but can't find the answer and although I've tried, I'm nowhere near good enough at VBA to try and use common sense to work it out. Is this something that can be done? I'm okay with computers generally and with Access too but I'm aware there's an awful lot I don't know and this is why I'm trying to do new things and learn stuff that I've not used before. I have tried all day to get this to work but am admitting defeat and am hoping somebody here will be able to help me. I'll probably need 'idiot level' advice if that's possible, I know my limitations. :)
Do you know how to use the Event tab in the Property Sheet? You can set all of your fields to [field].Visible = True on either: On Current, On Load, or On Open
Screenshot of the Property Sheet and for the field that determines the visibility of all of the other fields; you can use the Event: After Update so that way when you click/tab away from that field, it'll make those changes for you!
Property setting affects ALL instances of control. Control will be visible/not visible for all records depending on conditions of current record. Therefore, dynamically hiding controls on form set in Continuous or Datasheet will NOT give the desired result of
only work on the current record and not all of them at once
Db is not going to 'remember' dynamic setting - code needs to be executed when form opens and/or navigating records - so it is needed in OnCurrent event as well as control's AfterUpdate.
Conditional Formatting can dynamically enable/disable textbox/combobox by record although control is still visible.

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.

Adding a "New Button" option on Access form

Please forgive me if this question is too vague or extensive. I have limited experience with Access, SQL, and VBA and have a problem at work that I just can't solve. I'm trying to add a "new button" button to the user interface on our Access database.
I would like it to maybe bring up another form that allows you to input a query you want to make into a quick link on the home page. Obviously this would only be accessible to certain users but I can handle that part.
I don't necessarily need the code written, just an idea of where to start. So far all I've been able to do is hard code a new query or link into a button each team I want to make one. I want this process to be simplified so that anybody can make a button even if they don't know how to use Access very well.
Again, any help would be greatly appreciated and feel free to tell me to get lost if this is too vast or general a question.
I would like it to maybe bring up another form that allows you to input a query
The above seems very confusing. You are asking how a form can be used or launched or displayed to allow the user to add a new record. Then you toss in this VERY unrelated concept of some query? What does some query have to do with adding a new record?
If you want to add a new record, and you are in a form that is displaying current records, then behind the button, you can execute this line of code to jump to a new record ready for data entry:
DoCmd.GoToRecord , , acNewRec
So, that is one line of code.
If you want to launch an existing form and have it start out with a new clean fresh record, then use this:
DoCmd.OpenForm "frmCustomers", , , , acFormAdd
The above will launch the given from in "add mode" and thus you are again on a new fresh record ready for data entry.
The issue(s) of some query etc. for the user What does that have to do with wanting the user to add a new record? So that part does not seem to apply to the basic idea of presenting a form with a new record which allows the user to add that record in question.
You have to explain what all the hub bub about this magic query issue but to jump a form to a new record for the user? Just use the first line of code behind a button.
And if you need to launch a form in "add mode", then use the 2nd example one line of code behind the button in question. None of this has really anything to do with some "query" in regards to you wanting the user to add a new record. You can expand on what you mean by some user query, but you have several options to jump an existing form to a new record, or launch a form in "add mode" to allow adding of a record. In these cases, you don't need nor want to write or deal with some SQL query.

Access Field Not Refreshing

To start, I am using Access 2003 and have a similar project that works correctly that I designed.
I am stumped as to why a particular field will not change dynamically like every other field until I "refresh".
Currently I have a task list that lists all items that need to be works. Containing a Status: New, Open, Closed; The account number, person who is working it and more.
The tasklist is just a form with a subform with a datasheet view that opens the task when you double click it. If a user opens a task, that task will be locked until they move on. If any information that is viewed in the task list is changed, it dynamically updates, all but the Status (which really is the most important) until the user manually refreshes it.
Does anyone know what I need to look for that would cause this? The Status is stored as an integer that joins with it's true value. I thought this may be the reason, however I have a similar tool I designed does not have this issue.
I've look into how they are joined, the code that changes this value, everything seems the same between the working and not working.
Any advice?
Thanks in advance.
edit any fields that are JOINED, do not seem to dynamically update until I hit refresh. However, the other database has this working. What am I missing that is different between them.
Solved.
I changed the object displaying the field from a textbox to a combobox, showed two columns with widths 0";1" and it works.

How to Make Exception Handling on VBA Excel Form Combobox?

I have this userform that i'm developing for my report formatting task. My whole code is finished, there are only 2 problems that i need to work on.
Making my VBA application work on every excel file that user choose
Exception Handling for ComboBoxes on my form.
(Edit: I hope trying to get attention of people who are interested in this question to another stackoverflow.com topic is not against forum rules)
You guys can reach first problem's topic from here: (There is already one suggestion but i'm little bit confused. So it would be super for alternative suggestions) http://bit.ly/VnF3cK
And about my second problem, when i click empty place of combobox, i can type whatever i want, but i want to restrict it, so users can only choose values [1-5] that i put inside of combobox. How can I achieve this?
In answer to your secondary question, you need to change the ComboBox's Style property to frmStyleDropDownList