MS Access 2016: Avoiding entering the same data multiple times - vba

one of my table keeps track of assets that has been assigned to different customers. For example, I have a field named "Location" which is a list of devices and a field name "Customer"
The 1st 2 or 3 letters of "Location" is unique to the Customer's name, for example let's say the customer name is "All About Customers", my Location will be AAC001, AAC002, etc. The sequence continues indefinitely.
When adding records, I would type AAC010, AAC011, AAC012, etc. and then I would have to select from a drop down box which customer these belongs to, if I'm adding 40 records, I'd have to select the same customer 40 times.
Is there away to let access know which Customer I'm preferring to based on the 1st 2 or 3 letters of my location?

Not gonna talk about the flaws in this approach in terms of database modelling and rules etc.
But to do some vba code, you just have to define the OnChange event of the desired control e.g. TextBox
Whenever there is a character entered you could execute code.
(in example it would happen only if text has 3 or more characters)
Public Sub OnChange()
If Len(Textbox) >= 3 Then
'Do Something
End If
end Sub

My time is limited right now, so I can only provide you with my approach and not the actual code:
I would create a separate table named Customers.
The table should have the two fields (test data in parentheses):
customer (All About Customer, The Store)
customerAbbreviation (AAC, TS)
On your form, there should be a macro fired after the update of the form's Location field.
The macro should have some type of code that separates the numbers and text in the Location field. Using All About Company as an example, the macro should return AAC and 001.
You could search the Customers table for the customer whose customerAbbreviation is AAC.
You could then set the form's Customer field to the All About Company, or whatever's returned in the above line.

Related

Inheriting a field value based on a different one

There is table of people tblPeople, each have an ID field and a on vacation (yes/no value) field.
I have a form which inherits an ID of a person from a different form. Because both forms use a different table than tblPeople, that different table has only the person's ID field and not his vacation field, so I can't inherit the vacation field directly.
What I want is to get the vacation value for that person: I thought that I could create a combo box which has a record source: SELECT Vacation FROM tblPeople WHERE tblPeople.ID = Me.txtID which will return only 1 record, and then code it to automatically pick first value and keep it hidden or something. But that involves some pointless, clumsy, and ugly code.
My question is if there's an alternative method to doing this.
Base the form on a query that left joins in the vacation field. Then the field will display automatic and without code. And better is if the vacation value changes, then no update code etc. will be required – in fact this is the whole beauty of a relational database!

MS Access manual Auto incrementing field

Im building a system for my company to keep track of internal orders, inbetween our warehouses, we have material that goes out warehouse 1 to warehouse 2 and we kind of lose track of how much of "x" is in warehouse 1 and how much in warehouse 2, so i want to implement this access db where a user fills a form and says: order 1: 500 of "x" order 2: 300 of "y". then another user fills an exit form where he says 1 of "x" going out, so i would need the program to keep track of total order and how much as gone out to fill order 1 and so on...
My idea here is to have both an order number and an id number for each of "x" everytime someoneone assembles 1 "x" they fill the form and print a label directly from the access (i have this part working already) while keeping a record of when it was assembled, who verified and what was verified (it will work as a quality control also).
What i dont know is how to program the db so when it reaches 500 of "x", the id number for "x" starts again from 1
This is the one major issue with my program right now, i'm not experienced in access db's or vba, but im getting there with a tip and a trick from here and there, so, no need to be careful with the technical language, i will google it if i have to :p
EDIT:
The table structure goes as follows:
1 table as the main table where I record the check that is made for every product, where I include the model of the product, the said ID that I want to reset after a number of products checked, and a concatenated field that includes most of this information to generate a qr code.
Then there is a table for the Order Number, which is connected to a form to record each new order with a date/time field, the order number itself and the number of products. This number of products must then be called from the code that will count how many products have been checked to date and keep the order number field updated so we can keep track of the order.
Then there is another minor table just to get values for the form, the product models
Thank you for your answers ;)
See this MSDN Documentation
Unfortunately in Access, you cannot 'reset' an ID field, unless you move the records to a newly created table and use that table for every 500 records.
As for the user control and login form, I'm afraid those are separate questions that must be asked in a different thread.
To get you started:
You can set the RecordSource of a form to a table, and when users make entries, the data will be saved to the table. You can also use a form with controls (text boxes, comboboxes, etc.) and create a button that runs a query to insert these records into a table.
The login piece - you can encrypt the database with a password. That may/may not be sufficient.
I would suggest you change your schema, if possible. Something like the following:
Orders
OrderID (Autonumber)
ProductID (link to your Products table)
QuantityRequested
Deliverables
DeliverableID (Autonumber)
OrderID (link to your Orders table)
SequenceNumber: in the BeforeInsert event set this value equal to:
DCount("*", "Deliverables", "OrderID=" & Me.OrderID) + 1
I'm assuming that your form has a control named OrderID that is bound to the OrderID field of the Deliverables table.
The code uses the DCount() function to get the count of all the other deliverables that have already been created for this order. If this is the first deliverable, DCount() will return 0. It then adds 1 to this count to get the sequence number of the next deliverable.
If the new SequenceNumber is greater than the quantity requested, you could display a message saying that the order has been filled and cancel the creation of the Deliverable record.
This is just one approach and it is not a complete solution. I'm assuming that once assigned a sequence number a deliverable cannot be deleted. You might need to make allowances for deliverables that get lost or damaged. You could incorporate a status field to the Deliverable table to deal with this, but you would still need to make a decision about what to do with the SequenceNumber.

Applying a filter of unknown elements using array. Or hiding select records from user

Using a split database, everyone gets a front end with a local table I use as a 'cart' like in online shopping.
I'm copying records to a local table from stock. I don't want the record I copied across to be allowed to be transferred over again making duplicates. I also don't want to delete the original record, just modify it.
So I want them to edit the records copy locally then hit a button that will update the record on the database back end. If they don't hit the button and close the front end, no changes are made. Assume the temp table is wiped on start up.
To stop duplicate records I want to hide select records from the particular user of the front end database only. So if the Access app crashes the record isn't hidden for all users.
Idea: What If I add a Stock_ID (hidden) field to the local table? Then I can poll the column and if any Stock_ID matches the ID of the record I want to copy a message box says Error, record already exists and cancels the record copy?
I think you're saying you want to show the front end user only those stock records whose Stock_ID values are not present in the local table.
If that is correct, you can use an "unmatched query" to display those stock records.
SELECT s.*
FROM
stock AS s
LEFT JOIN [local] AS l
ON s.Stock_ID = l.Stock_ID
WHERE l.Stock_ID Is Null;
The Access query designer has a query wizard for this task. It should be worth a look.
When you say "hide select records", what combinations? Hide all of a certain type from ALL users; hide certain records from SOME users? In your split database, does EACH user have a copy of the front-end, or do all share the same front-end? There must be some criteria that determines who sees what records? Once that is identified, then a solution can follow.

MS Access- Table normalization and query design problems

I have a tricky thing I'm trying to get working
I have a table that contains events, and 10 fields populated with ID Numbers of employees who attended, and a comment box for each one. I tried to create a query that uses a combo-box with the ID Number to Search for the events they attended, and display them in a form cleanly (IE without displaying other peoples, or having a large number of text boxes everywhere). I got it partially working but I could not figure out how to go any farther. I can't figure out how to separate out the fields by the people. I was toying with the idea of having the event listed say 10 times with one person per record but that would cause alota bloat.
Any ideas how to do this? Different formats/other approaches would be great as well.
Thanks guys.
I would split the tables... have one that contains the event, with an eventID field as an AutoNumber. Then have another table called Attendance with three fields: eventID containing the ID of the event, employeeID, and Comment for the comment. This would then even allow you to create another table containing more info about the employee like first name and last name for use in reports.

MS Access 2007 - Select multiple records and assign a value into a field

I am using a Multiple Items Form to list CASES (records) where there is no TECHNICIAN assigned (Maybe I should use a Datasheet to list the records?).
I would like the user to select a TECHNICIAN from a dropdown field that gets its values from an Employee Table (I can do this). Then I would like the user to select multiple CASES (records) in order to assign that one TECHNICIAN to the Technician field in all of the selected CASES.
Basically, I'm trying to keep the user from having to assign a technician from within each and every incoming case request. I want them to "batch" assign a tech to multiple cases.
Can someone point me in the right direction?
Ok so I did some more research. This may not be the best answer but it works for now.
I created a Multiple Item Form.
I added an unbound dropbox that lists Employees from the table
I added a button on the detail section (for each record) with the follow line of code:
Me.Technician = Me.Choose_Technician
Now the user can pick a technician from the dropdown and then click the button to assign that technician to the record/casefile.
This is a simple solution if you only have a couple of records/casefiles to assign. If the amount of incoming casefiles increases there will have to be a way to select multiple records using the shift key. I'll keep researching this.