I have the following tables:
1.Students -
ID (pk)
-
Urdu Name
-
English Name
-
....
-
....
-
2. Classes -
ClassID (pk)
-
Grade
-
Section
-
....
-
....
-
3.Students and Classes -
StudentID (related to Students.ID) | PK
-
ClassID (related to Classes.ClassID) | PK
-
RollNo
-
....
-
....
-
4. Student Attendance -
ID (PK)
-
Student (StudentID)
-
Attendance Date
-
Status
-
Now the issue is that when I make a select query from the tables "Students and Classes" and "Student Attendance" related by StudentID and Student, the resulting query is not updatable. The Query is: -
SELECT
-
[Students and Classes].ClassID
-
, [Students and Classes].StudentID
-
, [Students and Classes].RollNo
-
, [Student Attendance].[Attendance Date]
-
, [Student Attendance].Status
-
FROM
-
[Students and Classes]
-
LEFT JOIN
-
[Student Attendance]
-
ON
-
[Students and Classes].StudentID = [Student Attendance].Student;
-
The record is not updatable.
Waiting for any help.
9 2490 jforbes 1,107
Recognized Expert Top Contributor
It sounds about right that your Recordset is not updatable. This may help you understand a little better of what is acceptable and what is not acceptable for the basis of a Form when you want it to be updatable: Why is my query read-only?
Another way to put it is using One-To-Many Joins makes your Recordset Readonly.
Typically in a situation like yours, where you want to update records in multiple tables (or display information from multiple tables), you create a Main/Subform setup where each Form is based on a single table.
I have a form that Shows ClassID from table "Classes", with a subform showing StudentID's from "Students and Classes" table. The other form is required to show "Students, Attendance Date, Status" from the "Student Attendance" table for the studentID which have ClassID equal to the ClassID on the former form and the latter should be updatable. Is there anysolution please?
jforbes 1,107
Recognized Expert Top Contributor
I don't currently use Access as my backend database, so I'm a bit rusty on Access' capabilities regarding this. It doesn't quite play by the same rules as SQL Server, and there may be a way to get it updatable by Defining the Relationships of all the tables involved. But I can't guarantee that.
In a case like this, I typically create the SubForm based on the base table (non-query) and then either use a Filter to narrow it down to the Records specific to the MainForm, or supply the an entire RecordSource Select Statement. This is usually updated/assigned to the SubForm in the MainForm's OnCurrent Event. Also in the MainForm's OnCurrent Event, any default values (like Foreign Keys) are defined for the SubForm.
This approach gets a little tricky in the case of a LinkTable, which is what [Students and Classes] happens to be. Especially when Adding a new link, like enrolling a Student in a Class. To make this happen is typically more complex than navigating to the NewRecord and typing in some stuff. It usually takes navigation to one Record (like Classes) and then clicking a button to look up the second Record (like Student) and then clicking another button which takes the two pieces of information and formulates an Insert Statement against the LinkTable and then executes it.
I am still not understanding what to do...
I think that I understand now what is happening. You need to change your table design for [Students and Classes] to have a single field primary key field instead of a composite key as you have now. You would then change [Student Attendance] to link to this new field instead of the student ID.
This is a good idea. I appreciate for this idea. But then, is there a way to preven any duplicate stdent for on class or a duplicate class fo one student in the students and classes table?
It can be done via a multi-field unique index constraint, but personally I would recommend doing it via code (like a DCount() function to see if a record already exists for a particular student and class) as that then allows me to provide a custom error message instead of getting one that Access generates that users won't be able to understand. On your form's BeforeInsert event, just run the test and if a record already exists, then set Cancel = True to stop in insertion of a new record.
NeoPa 32,556
Recognized Expert Moderator MVP
I'd recommend doing it in both if you want a code solution.
It should always be set up to have a unique compound (multi-field) index.
Code can be got around. Tables can be accessed directly. Relying solely on the code is not a wise approach.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: John Baker |
last post by:
Hi:
I have two tables, a setup table (TblSetup) and a purchase order table (tblPO).
When i construct a query with ONLY the tblPO shown, and a type in parameter for the PO
number, I an update...
|
by: John Baker |
last post by:
Hi:
Most of the time when I do a query and it has no matches, there is a single blank line in
the result that I can test. I have one query where no result produces a response with NO
lines at...
|
by: Mario Zoratti |
last post by:
Hello, everybody,
Please be so kind to explain how it is possible to make a query pass
through in Access 97 vs SQL server updatable. The query is "SELECT
CDC. * FROM CDC": it is very simple and...
|
by: Johnny M |
last post by:
I have been using Access since office 4.3. I have just upgraded to Office
2003 and am having issues with creating updatable queries. If I link one
table to a selection query based on the same...
|
by: GD |
last post by:
tblFoo
FooId Name Number
1 One 1
2 Two 2
3 Three 3
The Following query produces the results I want, but it is not
updatable. I need at least the...
| |
by: Enterprise |
last post by:
Hi,
Here is my code for the Union query "Table
union Table union Table ;"
The tables are actually queries themselves.
I made a form for the query, but when I try to update the...
|
by: Apple |
last post by:
I had create a query with one table and one query, and then create
form with that query using wizard, but I can't append or edit data in
that form & query. Please help!
|
by: adolph |
last post by:
I created 2 tables, each with an autonumber primary key. Fields are:
ID (autonumber Primary key)
Number (single)
Color (Text)
FName (text)in one table and LName (text)in the other
What I'm...
|
by: CC |
last post by:
Dear all,
Following Many-to-Many table structure is part of my database
-----------------------------------
TbGeneral (dossier information)
PK: dsr_id
TbDossierSample
PK: dsr_sample_id
|
by: usr123 |
last post by:
I have got a very simple sql query in access, and i m trying to update the record in the table. It is coming up with the error that use updatable query.
What do i need to do to make my query...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |