Search code examples
ms-access

MS Access: Edit calculated field for each unique record


This is my first time posting here so I apologize in advance if I don't use the proper etiquette or if this question is too wordy.

Just to give a little backstory, I have created a receiving database that compares part numbers and quantities that our operators have physically received vs the part numbers and quantities shown in an electronic invoice sent from our plant in India. This invoice is an excel file that i append to a table in access with the fields "Invoice Number", "Part #", "Pallet #", and "Quantity" (plus some other fields but they're irrelevant to this issue I'm having).

We have a second facility right down the road where we keep most of our inventory. Our goal is to create a packing list for each pallet of units, after they have been received and checked against the invoice, that we send to our second warehouse (let's call it WH2). This packing list is a report generated from a form where users enter an invoice number and pallet number into uncontrolled textboxes that are parameters for a select query which is used as a subform in datasheet view.

Since our receiving team has to repalletize the pallets received from India onto new pallets for shipping to WH2, they need to be able to select unique records that they want the report to use for generating the packing list to help our operators in WH2 easily and accurately manage their inventory. So far I have this working exactly as I need it to. The only issue I have is that I want a quantity field to be created by the select query that defaults to the "Quantity" field value from the source table, but i want the users to be able to edit that quantity without it editing the value in the source table. I've tried creating an expression in the select query that equals the "Quantity" field value, but in the form it won't let me edit that field since it is calculated. I tried creating an uncontrolled field and setting the value of that field to equal the "Quantity" field value via VBA, but if I edit one value in that field it changes all values for that field in that record set to the same value. I essentially want this new field to default to the same value as the "Quantity" field from the table but still be able to edit each unique record. Sorry for the lengthy question, I wanted to provide as much context as possible without having to post my database since I have company information and name/logo and stuff like that. Btw I'm using Access 2016 and this is my first foray into vba, sql and access in general. If my scenario doesn't make sense the way that I've laid it out and you need my database to help me out then please let me know.


Solution

  • Then you need a textbox bound to another field to enter this other quantity. Use code to enter initial value into field. The real trick is figuring out when to do that. Perhaps when primary quantity is entered - use textbox AfterUpdate event:

    If IsNull(Me.tbxQty2) Then Me.tbxQty2 = Me.tbxQty1