Inheriting a field value based on a different one - sql

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!

Related

MS Access 2016: Avoiding entering the same data multiple times

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.

Ms Access SQL Limit control by previous field value

In a recipe database I have two tables. One has the ingredients of every recipe [Recipe_ingr] and the other the available measures and weight for every ingredient [Weight2].
When I input a new ingredient for a recipe, I would like to be able to choose the available units for only that specific food.
I have tried with this expression in the control field but it prompts me to choose first, and then the options remain the same for all the records, not changing dinamically according to the record ingredient code.
SELECT [Weight2].[Msre_Desc], [Weight2].[Gm_Wgt] FROM Weight2 WHERE Weight2.NDB_No Like Recipe_Ingr.NDB_No ORDER BY [Msre_Desc], [Gm_Wgt];
Picture of my tables
Update:
I tried the syntax change suggested by June9 but still the control doesn't update automatically with every record as you can see in this picture: Table
Suggest you name controls different from fields they are bound to, like tbxNDB. The SQL needs to reference a field or control that is on the form. Also, LIKE operator without wildcard accomplishes nothing that an = sign wouldn't. Also recommend not using exactly same name for fields in multiple tables.
If you use that SQL statement in combobox RowSource, try:
SELECT Msre_Desc, Gm_Wgt FROM Weight2 WHERE NDB_No = [tbxNDB] ORDER BY Msre_Desc, Gm_Wgt;
You want to save Msre_Desc as foreign key, not a record id generated by autonumber?

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.

SQL query in Access

Basically, I've been trying to make this query work for a while in Access and it's really frustrating me so instead of playing around with the criteria, I've decided to just do it in SQL instead but I can't quite figure out how to do this bit.
What I need to do is create a query that shows which members haven't returned an item that they're currently taking out on loan. If possible I'd like to include a calculated field to state the date is was due back and how many days late it is.
The fields I'm using are as follows;
Table = Loan
Toy Name
Hire Date
Duration (in days)
Returned Date (if it hasn't been returned, the cell is blank)
Table = Toy
Purchase Price
Hire Price
you wrote:
a query that shows which members haven't returned an item
your table does not have members in it. secondly table toy have nothing related to toy like toy name or something. Please provide further detail of tables.
one more question what is the meaning of blank? Is it Null or blank string?

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.