I am creating a Training Records database.
Tables: EmployeeList, RolesPerformed, SkillsNeeded, Courses, EmployeeRoles (Junction of EmployeeList and RolesPerformed), RoleSkills (Junction of Roles and Skills), SkillCourses (Junction of Skills and Courses). I can query to find out what courses an employee needs based on their roles. But I need to make another table to track the courses per employee and their date completed. When creating an Employee the user sets their Roles. I would like to auto populate the EmployeeCourses table with the needed courses.
I tried to use an After Insert event on EmployeeRoles, but it claims a createRecord cannot be used in a foreachrecord.
Do you have a table that defines what courses go with what roles?
The real trick is figuring out what event to put code into. Perhaps AfterUpdate for a combobox to select Role. Will probably also need code that first commits the new employee/role record to table.
VBA could be like:
If Me.Dirty Then Me.Dirty = False
CurrentDb.Execute "INSERT INTO EmployeeCourses(EmpID, CourseID) SELECT " & Me.tbxEmpID & " AS EID, CourseID FROM RolesCourses WHERE RoleID = " & Me.cbxRoleID
To prevent duplicate employee/course entries, set compound index on the EmpID and CourseID fields in EmployeeCourses.
Related
I have two tables:
'tableStudent' - a list of students given an ID number by the table, with following columns:
student_ID
last_name
first_name
and 'tableProject' which gives each project an ID and will be used to store information about the students involved in the project. Students will work in pairs on the project. This table includes the following columns:
project_ID
project_title
student1_ID
student2_ID
The columns student1_ID and student2_ID are combo-boxes that link student_ID to the student names.
I want to create a form that can be used to record students involved in a project. I want to be able to select the student IDs and have the student names autofill on a form.
I can make a form that autofills, but only with one student with this SQL:
SELECT tableProject.project_ID, tableProject.project_title, tableProject.student1_ID, tableStudent.last_name, tableStudent.first_name
FROM tableStudent INNER JOIN tableProject ON (tableStudent.student_ID = tableProject.student2_ID) AND (tableStudent.student_ID = tableProject.student1_ID);
When I add Student 2, I get a duplicate error on the student names. How do I indicate that the two names belong to different students? This is the code I'm generating:
SELECT tableProject.project_ID, tableProject.project_title, tableProject.student1_ID, tableStudent.last_name, tableStudent.first_name, tableProject.student2_ID, tableStudent.last_name, tableStudent.first_name
FROM tableStudent INNER JOIN tableProject ON (tableStudent.student_ID = tableProject.student2_ID) AND (tableStudent.student_ID = tableProject.student1_ID);
Any help appreciated!
Options for displaying related info from lookup table:
Use Access query designer to build form RecordSource. Pull tableStudent into query designer. In your case pull in twice - second instance will get named like tableStudent_1. Join each to one of the student fields. Bind textboxes to both sets of lookup table fields and set them as Locked Yes to prevent edit.
Don't include lookup table in form RecordSource at all. Include all student info in combobox RowSource. Expressions in textboxes refer to combobox columns by index, index begins with 0: =[comboboxName].Column(1)
DLookup() domain aggregate function, however, since your tables have a relationship, this is an inefficient method.
For all options, set textboxes with TabStop No.
I have 2 tables, customers data and activity. The customers data table has information like customer id, customer name, etc. What I want is when I input the customer ID in activity table, the customer name fill itself automatically, How can i do that? Thank you.
Use a query to link the two tables together by Customer ID. However, if you want to display the name on a form that is bound to the Activity table, you can use a DLookup on a field.
=DLookup("CustomerName","CustomerTable","[CustomerID] = " & me.CustomerID)
So I have 2 tables; a task table and an employee table.
A task is created by an employee and maintains the id of the employee that creates it as creator_id.
A task is assigned to an employee and maintains the id of the employee it is assigned to as responsible_id.
The creator of the task and the employee it is assigned to can be different people.
How do I write a select statement that allows me to display the full names of both the employee that created the task and the employee that is assigned to it.
I think it might look something like this:
SELECT Task.Description, Employee1.name, Employee2.name
FROM Task, Employee Employee1, Employee Employee2
WHERE Task.creator_id = Employee1.id
AND Task.responsible_id = Employee2.id;
I have tried variations of this but it either returns errors or hits the memory limit.
Where am I going wrong?
From your description the query is correct but you should consider rewriting it to use explicit ANSI joins:
SELECT Task.Description, Employee1.name, Employee2.name
FROM Task
JOIN Employee Employee1 ON Task.creator_id = Employee1.id
JOIN Employee Employee2 ON Task.responsible_id = Employee2.id;
Sample SQL Fiddle
I need to set up a small database as an assignment after 3 hours of an access introduction and I'm failing completely. However I youtubed several hours but still no change in the outcome. Do I try to implment too many excel functions into access?
I saw in one resolved question that it if calculation is possible in access?
I have three tables for a dvd rental business. Customers, Movies, Rentals.
My questions / problems:
I wanted to do an age check in regards to the customer's age and the age restriction of the movie. I have customer's date of birth and the age restriction for a movie. Provided fields DoB 15/03/1996, age restriction 18+. For example user is born 15/03/1996 and wants to rent a movie 18+. Access should show me the customer's current age like: Field name: Age; "17". This didn't work out at all. I failed in the first step to set up the field/calculation.
In excel it's usually =INT((TODAY()-DoB)/365.25) which tells you the age up to date.
How do I need to set it up?
Many thanks in advance
Nina
You need to convert the Excel formula to use VBA functions. Since Int exists in VBA, and the Excel UI, VBA and and Access database engine (DAO/ADE) all use the OLE date/time format, the conversion is pretty trivial - just use the Date function in place of TODAY.
So, say the tables are set up like this:
Customers - CustomerID (AutoNumber, primary key), Surname (Text, required), Forename (Text, required), DoB (Date/Time, required)
Movies - MovieID (AutoNumber, primary key), MovieTitle (Text, required), MinAge (Number/Byte)
Rentals - RentalID (AutoNumber, primary key), CustomerID (Number/Long Integer, required, foreign key to Customers.CustomerID), MovieID (Number/LongInteger, required, foreign key to Movies.MovieID)
You could then create a query called RentalsWithAge as so:
SELECT Rentals.*, Movies.MinAge, Int((Date() - Customers.DoB) / 365.25) AS CustomerAge
FROM (Rentals INNER JOIN Customers ON Rentals.CustomerID = Customers.CustomerID)
INNER JOIN Movies ON Rentals.MovieID = Movies.MovieID;
(Do so by going to create a new query in the UI, before cancelling the table prompt and heading straight to the SQL view.) Next, create a form to log a new rental, and base it on RentalsWithAge (not Rentals); ensure all the fields discussed have been added to the form, then handle the form's BeforeUpdate event as so:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.CustomerAge < Nz(Me.MinAge, 0) Then
Cancel = True
MsgBox "Customer is under the minumum age for the chosen movie!", _
vbCritical, "Customer Under Age"
End If
End Sub
With this kind of design, I would like to create a functionality with which to add and delete records from the junction table.
The case is from when editing an employee and selecting what exams they can take. In the left list box would be the exams that they aren't eligible for (yet, anyway) and the exams that they are eligible for on the right list box.
The table is something like this:
TABLE EmpExam
(
EmpID,
ExamID
)
The EmpID would be known at all times, but the ExamID would be selected from the left list box. Records in the right list box would probably have to have both the EmpID and the ExamID in order to be deleted.
Instant deletions/insertions aren't necessary once they're into their respective boxes are not necessary (they can wait until the form is closed).
Is there a good/standard way to accomplish this in Access?
Why use listboxes when you will have to add items to the table using code and then delete them using code?
For what you want to do, a subform is the usual solution. Furthermore, you can use the recordsetclone of your subform. Note that you should probably have a datetime field in that setup. Also, if ExamID is unique, and cascade delete is enabled, deleting from the main table will delete from the subtable.
I ended up using two listboxes with 1 add button and 1 remove button that triggers their VBA On Click methods that execute raw SQL.
The method looks something like this:
If IsNull(cboInEligible.Column(1))
Exit Sub
End If
CurrentDB.Execute ("INSERT INTO tblEmpExam (ExamID, EmpID) " & _
"VALUES (" & ExamID & ", " & lstInEligible.Column(1) & ")")
lstInEligible.Requery
lstEligible.Requery
The delete query is similarly done.
The two listboxes are mutually exclusive.
SELECT EmpID, EmpName
FROM Employee
WHERE EmpID NOT IN (SELECT EmpID FROM tblEmpExam WHERE ExamID = [txtExamID]);
txtExamID is a hidden (but obvious to the designer) control on the form since I can't refer to the form's ExamID except through a control or through absolute naming.
The other list box has EmpID IN instead of EmpID NOT IN to make it exclusive.