MS Access 2013 - Populate Fields Based on Check Box - checkbox

I have a form set up for data entry for new orders. When entering a new order a customer can be selected from a combo box. Shipping address, zip, state, etc. are in each customer record.
When a new order is made, the shipping destination may or may not be the the address attached to the customer.
I would like to add a check box to the form that when checked auto populates the shipping information fields to the customer's information. What would be the simplest way to achieve this?
Thanks

You should use the On click event of the checkbox.
Private Sub Checkbox_Click()
If Me.Checkbox = True Then
Me.TextboxShipDest.Value = Me.TextboxShipAdress.Value
Else
Me.TextboxShipDest.Value = Null
End If
End Sub

Related

Order sub to click userform commandbutton from sub

I am writing here because I cannot seem to find the answer on the internet.
Context of my sub and userform : I have several pivottables in the same sheet in a workbook.
These pivottables may have random names given by other users changing them unintentionally or not knowing the names are essential to the rest of the code. This is why i created a userform which has on one side the ideal name of each pivottable, and on the other side, comboboxes with the current names, like so:
pivottable dealing with x // combobox with all current names (user has to choose which one of the current names corresponds to the this pivottable)
pivottable dealing with y // combobox with all current names (user has to choose which one of the current names corresponds to the this pivottable)
pivottable dealing with z // combobox with all current names (user has to choose which one of the current names corresponds to the this pivottable)
and finally a button "VALIDATE"
here is a screenshot of my userform : enter image description here
WHAT I AM TRYING TO DO :
since the user has to inform the userform which pvttable corresponds to which title, i have written :
userform1.show vbmodeless
so that the user can go check the current titles of the pivottables and associate them with the correct one. Because I have put the vbModeless, the sub does not wait for the user to validate and thus fills the title with nothing or blank as nothing from the combbox has been chosen since the user hasn't had the time yet. Therefore, I want to signal that once and only once i clicked on "valider", then the sub changes the current titles to the ideal titles (can only do in the sub and not in the userform because i actually use an array that is subject to changes in the ideal names, and I can't put it in the userform because it is defined above in the sub, ican't pass it over to the userform). I am triyng to use something like :
if userform1.commandbutton1.click = true then
'and put pvtnames = userform1.combobox1.value
(but i am alright with the pvtname part). IS THERE A WAY TO CODE THE BUTTON.CLICK PART ? thank you ever so much for your help, i am sorry for the long message

MS Access Foreign Key Record Fill Too Fast

I have a problem with one of my forms in my MS Access database, and strangely it's the only form that has this problem.
The form has a typical Master/Detail structure, with the subform tied to a table. The subform record source includes a foreign key that pulls information from another table and populates the rest of the fields based on the key value. This foreign key is a Material number that defines a specific object in an inventory, and the other fields in the subform show details of this object.
Example from Signs table:
Material number: 116063175
StorageBin: A116
Material Description: Stop Sign
Dimensions: 48x48
All of this information is contained in the same table, but the form is for a table that is used to fill in what signs are on a particular road (stops, speed limits, etc.)
On all my other forms, when I type in the material number and shift focus anywhere else, the rest of the forms will fill in automatically. This process works here too, but for some reason Access wants to try to fill in the rest of the field data before I have finished typing the material number. I'll type "1" and access will throw an error that it cannot find a matching record in the Signs table in the foreign key's table. After rejecting the error twice, the data entry can resume as normal, which is also strange.
I hope I've been clear enough, this is my first time asking a question here.
Thanks in advance!
Edit: Tried re-building the form, same issue. Built another form similar but without my multiple comboboxes, didn't have the issue! Could this be due to underlying requery code in the Afterupdate event of my comboboxes? I have a cascading combobox setup on the form, could data entry be triggering a requery?
Edit2: for the time being, a fix that I am using is to make the material number and quantity (the two important fields for this form) into text boxes outside the subform, that the user can edit then place in the subform with a button click, which is coded as so:
Private Sub Command1_Click()
If Me!PrimaryRoadInventorySubform.Form.Dirty Then
Me!PrimaryRoadInventorySubform.Form.Dirty = False
End If
Me!PrimaryRoadInventorySubform.SetFocus
DoCmd.GoToRecord , , acNewRec
Me!PrimaryRoadInventorySubform.Form!MaterialNumber = MaterialNumtxt
Me!PrimaryRoadInventorySubform.Form!Quantity = Quantitytxt
End Sub

Unable to pass value from one form to another - Ms access

I have a multiple VBA forms, the first form takes user's name from a combo box and saves it in a global variable, code is below :
Option Compare Database
Public emplID_global
Private Sub OKLogin_Click()
If Not IsNull(Me.Combo_emplID) Then
emplID_global = Me.Combo_emplID.Column(1)
DoCmd.Close
DoCmd.OpenForm "NavFrm", acNormal
End If
End Sub
Now in my other form I have a combo box in which I want to auto-populate the valueof that variable, on load of form, which i saved using previous form, below is the code :
Private Sub Form_Load()
Me.AdvName = emplID_global
Me.DataForm.Form.Recordset.MoveLast
End Sub
but it is not working, It is not doing anything. I want to use this kind of code in all the forms.
Can someone please suggest what is the mistake in my code, i am fairly new to VBA. Thanks in advance :)
Add a field to your underlying table for the owner of that particular record. (I just called it Owner.)
Add the following code to your form:
Private Sub Form_BeforeInsert(Cancel As Integer)
Owner = Environ("username")
End Sub
Private Sub Form_Current()
Dim editable As Boolean
if nz(Owner,"")="" then
editable=true
else
editable = (Environ("username") = Owner)
End If
Form.AllowDeletions = editable
Form.AllowEdits = editable
End Sub
This is a fairly generic solution that does the job. Environ("username") returns the user's windows username. This is not necessarily all that secure. A person could go to the command prompt and edit the username environment variable so that they appear to be another person. This will definitely not keep out the NSA or anyone else with a little computer knowledge and bad intentions. But it will keep the honest people honest.
Explanation:
The BeforeInsert runs as a new record is being saved. In this case, it sets the record's Owner field to the user's Windows username.
The OnCurrent portion runs every time a new record is displayed. The code will check to see if the current Windows username matches the username stored in the record's Owner field and set the forms AllowEdits and AllowDeletions flags accordingly. Also, if the Owner field is null (as in the case of a new record), editable will be set to true. If you wanted to really emphasize the fact that the user shouldn't be changing things, you could also enable/disable the individual text boxes...
TextBox1.Enabled=editable
ComboBox2.Enabled=editable
... etc.
Simple solution. Keeps honest people from overwriting each others' work. I use this approach a lot.

Clear Access Form fields for Insert

I have done doing form in access for inserting records.
When open that form the field inside it appear filled with previous record l want them to be empty for allowing the user fill the filed, what should I do please!
If you just want to go to a new record just use the following in the load event
private sub yourformname_load()
docmd.gotorecord acdataform,"yourformname", acNewRec
'or
'docmd.gotorecord ,, acNewRec
To keep them from viewing previous records
me.navigationbuttons = false
To allow them to view just not edit previous records
me.allowedits = false
If you want to go to another new record when they click the ok button just put the same docmd... in the Click event of your button.

How can I get the ID of a record when it isn't mentioned on a form in Access 2007 via VBA?

I have a multiple items form which does not mention the ID of the record. I have a button for each row which, when clicked, opens up a new form containing more details.
In the past, I've added a field for the ID but made it invisible, but this seems silly - the ID is a unique field of the original query, so I should be able to access purely with code somehow.
Does anybody know how to do this? Let me know if you want more clarification.
Update
The fastest way for me to do this is to add a field in the form for the field in the query, call it the query field name, save it all and close it, then delete the field. Though of course I'd rather just be able to do Me.ID without any of that prior nonsense.
In some cases, you may have to refer to Me!ID, rather than Me.ID because the field has not been added as a property of the form (discussion: http://tek-tips.com/viewthread.cfm?qid=1127364 )
When you add the ID as as control and then delete it, it becomes a property of the form, which is why your work-around works.
If a form's record source includes a field named "ID", you can access the field's value as a property of the form:
Debug.Print Me.ID
That works without a control bound to the field.
you probably need to edit the recordsource / query.. and add that column as an available field.

Resources