I have a form with a field for each of the 12 months in the current year. They are for full time equivalent values. I would like to create a button which will autofill the 11 fields Feb to Dec based on what I've entered for Jan. How do I best approach this in VBA?
Access 2010 - Auto fill form fields Feb thru Dec with Jan value
Collapse
X
-
Hello bperella,
Before we venture down this road, please take a look at the following article:
home > topics > microsoft access / vba > insights > database normalization and table structures
While there are some reasons to handle the table design as you currently have it, these are very few and may well lead you into greater difficulty as you progress with your project.
As for the VBA code, you've provided very little information about what it is you are actually entering into each record field; however, you can take a value in the current record and then loop thru the fields using aFor Eachloop. Depending on the needs, you might use a nested loop or even a record set. The code could be ran either by a command button somewhere on the form or from the after_update event of the control holding the January field information.
A few more details may provide us the information we need in order to point you in the correct direction.
One thing to note here, especially if you use a wizard, the form controls bound to a table/query on a form default their name to the same name as the bound field. For example, you may have a table named [Months_schedule d] with a field named [January]. When you add a textbox control to your form bound to this field, the default name will be "January." In many cases this will be fine; however, there will be occasions where the form may have issues in code. It's a good practice to rename the control, ie the text box name "January" might change to "txtbx_Janu ary"
Now this way if you do something like:
me![January] you are absolutely sure that you are referring to the form's underlying recordset's field name "January" and Me.txtbx_januar y you know you are referring to the control.Last edited by zmbd; Jan 22 '17, 08:04 AM.
Comment