Custom Queries in Microsoft Access 2010 - mysql

I am very new to using Access and databasing in general. I need to set up a database to manage car loans. I currently have the following:
A form which displays the information each individual customer
A button at the bottom of the form, titled "View Customer History"
A table with the records of all loans, sorted by car registration number
What I need to do is have access create a custom query which will display all the items from the table containing the loan records that have been rented by the customer that is being displayed in the form. I am aware that creating queries manually is an option but seems impractical due to the number of new customers loaning cars all the time.
I hope that the question made sense and appreciate any help I can get.

I would approach the task in this way:
Create two tables called "Customers" and "Loans"
"Customers" table should have unique records for each customer. One of the fields in this table will be titled "Name" and should obviously contain the names of the customers. Make this field the Primary Key. The other fields will contain other information related to the customer
"Loans" table will have a field called "Customer" which stores the names of the customer loaning out the car. Link this field to the Primary Key of the "Customers" table. The other fields will contain details relating to the loan
Now your form (name of form: "Information") is linked to the "Customers" table and shows all the information stored in the table. Name the field on the form containing the name of the customer as "CustomerName". At the bottom of the form you have a button for viewing customer history
Create the query: SELECT * FROM Loans WHERE Loans.[Customer] = Forms!Information!CustomerName;
Assign this query to the 'On Click' event of the button on the form
There are of course other ways of achieving the desired results, but the way described above is also sufficient.

Related

Trying to update record with a form, error: "The changes you requested to the table were not successful because they would create duplicate values..."

I'm creating a database that will be used to keep track of maintenance performed on equipment in a nursing home. I'm using MS Access 2010, and I'd say my skills are somewhere between novice and intermediate, almost entirely self-taught for this project.
The database structure is as follows:
tblAssetTypes:
TypeID (PK),
MaintenanceSchedule,
EquipmentType,
EquipmentSubgroup,
MaintenanceTime,
TasksRequired
tblUniqueAssets:
UniqueID (PK),
StorageLocation,
TypeID (FK)
tblPrevMaintRecord:
ID (PK),
UniqueID (FK),
DatePerformed,
TimePerformed,
MaintenanceComments
The UniqueID will be an identifier created by maintenance people, usually as four letters and then three numbers. I'm currently using "test001", "test002", etc.
I have a form that allows users to enter the UniqueID that has been assigned to an asset, select what kind of equipment it is, and where it is stored.
I'm currently creating another form which I want users to be able to select from a list of pre-existing UniqueIDs and then change the location that is stored in the table. However, as it is currently set up, every time I select a UniqueID from the combobox on the form, I get the following error. This error comes up after I have selected an UniqueID, and then if I try to do anything further, such as saving the record or even trying to close the form.
The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key, or
relationship. Change the data in the field or fields that contain
duplicate data, remove the index, or redefine the index to permit
duplicate entries and try again.
I'm sure I probably need to give more information but I'm not sure what will be needed so I'll edit as needed.
How can I update the location information stored in tblUniqueAssets for a UniqueID value that already exists? Surely I wouldn't need to delete the record first and then create a new one with the previous UniqueID?

Form database in SQL

I am trying to setup tables in a MySQL database for one of my class projects. The project involves us submitting html forms to a database. So currently I have a table for every form that I am currently submitting the to database. I also have a user table which holds user information.
My questions is I want to link the forms tables to the user table, but I am trying to avoid having to create a linking to table from each form table to the user table separately. Is it possible to not do this?
I am assuming each user submission is a row entry in the Form tables? Without the user_id column already in your schema, how did you differentiate which entry is which user to begin with?
For your question, it depend on what you want to output with these form tables. If all you want to do is to output the content of the forms for a given user, then adding a user_id column to each of your form table will suffice.
However, if a form requires some additional information about the user in the Users table, might as well add the user_id column as a foreign key to the Users table that you can join with.
I don't see what is the restriction to "linking to table", unless your have a lot of Form tables

Microsoft Access: Getting current record & creating child record before insert

In Access, I'd like to give the user a datasheet form to key in some data. This datasheet merges two tables together, a parent (Product) and a child (Book). I've linked them up using their IDs and they share a 1-to-1 relationship. However, while entering data, as long as I key in any Book data, the following error message shows up:
You cannot add or change a record because a related record is required in table Product.
And I am clueless as to what to do, so I thought that giving a administrator-only metadata to the Product table would help. When I set it to "Book" and create a new row in Product, a data macro will then programatically create a corresponding row with the same ID in the Book table. Does that sound feasible?
Anyway, I will need to retrieve the ID of the current record of the Book before insertion, so I wonder how'd I be able to do that.
Make sure the foreign key (=field with which the table is linked to its parent table) of the Book table is included in the underlying query.

How to create a data entry form that puts data in two tables

I have Student and Course Tables
Student
--------
ID - Primary Key - AutoNumber
Name - Text
Age - Number
Courses
-------
CID - Foreign Key
CourseTitle - Text
ID in Student table is linked to CID in Courses
Question
I want to create a simple Data Entry form that collects a Students Name, Age and Course Title. The Name and Age should go in Student table however, the Course Title should go in Course table.
How do I do this? I know how to create a data entry form that puts data in one table but don't know how to put it in two tables while maintaining the relationship. I would really appreciate a screenshot.
Assuming that each student can have 0 to many courses, you should create a subform on your data entry form with the courses for each student listed.
It sounds like you are doing this using the Access Forms designer (as opposed to VBA code):
Create a main form named frmStudents.
Set the datasource for this form to your students table, and then add the fields you want displayed (You can drag these from the "available fields) menu.
Create another form named sfmCourses and set the datasource to your courses table. Set the default view for this form to either continuaous forms or Datasheet. While in design view you will still see a standard forms designer view. Drag and drop the fields you want available onto the form and arrange to suit.
Add a Subform container to frmStudents and set the SourceObject property to sfmCourses. Then use the LinkMasterFields property to establish the relationship between the two.
Hope that helps.

populate a many-to-many table with access

I have two tables (persons and projects) which are in a many-to-many table, thus linked together by a third table persons_projects
In ms access I now created a form showing data from the projects table.
What I want is to have a subform showing all persons- datasets which participate in this project. In this subform it should also be possible to add (or delete) persons from this project—a drop-down seems the best choice here.
How can I do this? I’m able to show all participants, but I’m not able to add them. seems like I have the “insert into view” problem again, since I need persons and persons_projects to show the correct datasets. but as I’m only changing/adding rows in a single table (persons_projects) I don’t see why access is bitchy again.
You should not need persons, only persons_projects. I assume that persons_projects consists of:
person_id -> FK ) Combined as PK, perhaps, if not, an autonumber PK
project_id -> FK )
and (recommended) a datetime stamp and user field.
The subform is set-up with a Link Child and Master Field of project_id, which will be automatically completed by Access, and a combobox similar to:
Control Source: person_id
Row Source: SELECT person_id, surname & " " & forename, some_field FROM persons
Bound Column: 1
Column Count: 3
Column Widths: 0cm;2cm;2cm
Edit re Comments
It is possible, though often a little more difficult, to include both tables and have an updatable recordset, the query (view) should include both project_id and person_id from the junction table.
Sounds like persons is the driving dataset here since you want to be able to link it to multiple projects as well as delete the person record.
Base your form on the Persons table. A subform should be based on the person_projects table and linked by the corresponding id's. You can use a combo box on the projectid in the subform and have some other field displayed so the user can identify the project (name?). You may want to show all the project data for each project on this form, but you may find it getting very confusing to the user. Having a separate form that you can 'pop-up' to give more project information may be a better choice.
If you want to delete a person, you can just delete from the persons table, but you need to decide if you want any orphan records in the person_projects table (Which you shouldn't). It's easy in Access to establish a link with referencial integrity (cascading update and delete optional). It's up to you as to how robust this needs to be.