Append Query using Access 2003 - sql

I am helping a small school with their database which I created three years ago and that works fine.
I am now creating a attendance register as a new feature to it and am struggling with the update query fields.
I have two tables and one append query which works well with the form I have created. I have combobox to filter the class to check the register which works well. The problem I am faced with is when running the query, it updates all 180 students and not the ones filtered per class.
I need to append the data only for the class selected. Thank You
Please help.
Harry

It seems that you wish to only update or append the rows that match the combobox on your form. You can refer to an open form in a query in MS Access. With your append query in design view, under the field that you want to match and type in Form! followed by the name of your form, another dot or exclamation, and the name of your combo, say:
Forms!Form1!Combo0
In SQL View an append query would look something like:
INSERT INTO Table1 ( AText )
SELECT Table2.AText
FROM Table2
WHERE Table1.ID=[Forms]![Form1]![Combo0]
Similarly for an update query:
UPDATE Table1b
SET Table1b.ADate = Date()
WHERE Table1b.ID=[Forms]![Form1]![Combo0]

Related

Drop-Down Box in a Selection Query - MS ACCESS

I'm working on a selection query in my Access database. in one of my columns I wanted to have a drop-down list with selected data. Unfortunately nothing is showing, and I'm thinking about two Problems that can be responsible for this :
The selection wont show up until I link my query to a table where I can modify and select from the drop down list.
I made a mistake in developing but can't find anything about that mistake
Here is the details of whats going on :
What I want
This image is just the result of my query not linked to a table
What I have
Is an actual drop down list without any data in it (still talking about the result of the query not linked to a table in which modification can be made directly)
Here is What I did
Added the queries and tables I'm working on and then =>
Selected the column I wanted it to be a drop-down list and then added the following query after changing it to a drop down list
SELECT [SALARIE_nom] & " " & [SALARIE_prenom]
FROM (T_STATUT_EMPLOI INNER JOIN T_SALARIE_EMPLOI ON T_STATUT_EMPLOI.STATUT_EMPLOI_id = T_SALARIE_EMPLOI.SALARIE_EMPLOI_statut_id) LEFT JOIN R_Select_Salarie ON T_SALARIE_EMPLOI.SALARIE_EMPLOI_salarie_nni = R_Select_Salarie.SALARIE_NNI
WHERE (((T_STATUT_EMPLOI.STATUT_EMPLOI_statut) Like "*validé*") AND ((T_SALARIE_EMPLOI.SALARIE_EMPLOI_Entreprise) Like "*RTE*"));
if I run the sql query on it's own, it gives me the results I want but when trying to see this result in the final table (result table of my query) I got the blank drop-down list.
here is the result I get from executing the query alone :
So I think it's working.
Thank you in advance for reading my explanation and for your comments
I think that everything was fine, and that it was just a bug. After linking my query to a form I started seing the data in the drop-down list in both the form and query.
But I still Have one small issue which is :
Not being able to modify or choose from my drop-down List.
What I did
I created my form using Forms Assistant in access and then I chosed as data source my query. But I can't modify my form or anything could please suggest something to me.
Thank you !

Count records from another table to include in the results of a bound table

I am using Visual Studio and have an Access database with a couple of tables that are related. They are using default drag/drop binding using WinForms to the dataset which was automatically generated as well.
I want the parent table to include a column with the count of the number of related records with that ID in the results. The tables look like this if it matters:
I added an additional query to the table adapter (as you can see from the screenshot) that does what it needs to do (without including the linked ID's) thinking that was how to do it. Am I at least on the right track? The query looks like this:
SELECT COUNT(*) AS WorkerCount
FROM (tblJobLaborTech INNER JOIN tblJobLabor ON tblJobLaborTech.JobLaborID = tblJobLabor.JobLaborID)
WHERE (tblJobLabor.JobLaborID = 494)
And of course I need to change 494 to something variable which will match the corresponding record when it runs, but
WHERE (tblJobLabor.JobLaborID = tblJobLaborTech.tblJobLaborTechID)
doesnt seem to preview at all (no value given for parameter)
so i also tried
WHERE (tblJobLabor.JobLaborID = #JLID)
which also doesnt preview.
But that's only the start of the problem. Let's say I can get that part working, how do I get the result of that Scalar query to run for each record in the calling query and return in the dataset as if it were another field in that table?
You don't need to do this using the DB. A datatable can count the records present along a child relation
In your tblJobLabor add another datacolumn (right click, add>>column) and set its Expression property to:
Count(Child(XXX).JobLaborID)
Replace XXX with the name of this DataRelation I've highlighted:
More information can be found by looking at the fairly lengthy documentation on DataColumn.Expression at https://learn.microsoft.com/en-us/dotnet/api/system.data.datacolumn.expression?view=netframework-4.8

MS Access Binding Textfield to tables

I am currently building a MS Access database as a project #Work.
The Database is fed with a huge, not sorted Table DataQueryExport, and the objective is to create a GUI that makes that huge table workable.
Now to the question:
I have a textfield Comment that is supposed to show a comment to a specific data entry WorkID. The WorkID Is stored in a seperate table called WorkID_Comments which is filled via SQL query. The Table WorkID_Commentshas 2 columns, WorkIDand Comment.
The GUI has a ComboBox WorkID_Combo, where you can select a specific WorkID from the main Table DataQueryExport. This exact value is what is supposed to be used as a reference to show the comment for that WorkID.
TL:DR; I need the Comment Box to show and store the Text I wrote for that Value selected in the ComboBox. How do I get the Textfield to show the Value from the Table WorkID_Comments.Comments where the Value in WorkID_Combo(View ComboBox) is the same as WorkID_Comments.WorkID
I apologize beforehand for any weird capitalizations, I am used to it, German is my main language.
Thank you for reading, I am thankful for any response.
Build a query in the query designer with your needed columns (If I understood it correctly: ID and the Comment).
Then go to your combobox and chose under properties recordsource table/query and your designed query.
Now you can specify which colums should be shown and use the ID as the value in the background.
Then bind another query to your form (here is the text you wrote as column) which is linked to the ID from the combox. Put a textbox in the form and use the column as source.

Why is Access trying to append several rows instead of a single from a form?

I have created a form in Access and added a query to insert a row into the database using the values in the form. When I run the query using a macro attached to a button the query appends the same number of rows that exist in the database instead of a single one. I can't understand why. Any help would be appreciated.
Your query pulls not the selected (current) record but all records of the source.
But don't use a query, use the RecordsetClone as shown here:
Duplicate Record with New Primary Key (VBA)
Hi thanks for the replies. It was because I had created a select query first from a Customer table and then changed it to be an append query. So when I checked the SQL for my append query the last line was "From Customer". When I removed this part the append query worked as directed.

MS Acess 2003 - VBA for Update SQL query?

hey guys, could someone show me the simple update query through vb? I need to add new fields to the table (just 3) and add a couple text boxes on a form so that users can add some additional data relative to the record (which is already what this form is based on).
So the first form I have is a form that populates a list, when the user double clicks on a selection from that list, it opens a new form, so that the ID of the the table that is tied to this form that I need to add the these text boxes on (all the combo boxes and text boxes relative to one record are tied to the active form at this point, however there are all unbound. On a button click there is already vb that saves the information to the table). I did not create this however, it was built by someone who is not there anymore, and apparently is better than I at this stuff. My problem is that there is soooo much vb that checks for records, and various sql statements based on case, that I cannot decipher it to its simplest form.
So I was looking for a simple example of an update sql statement in vb so I can try to break this apart.
I need it to update the record based on the ID: sql WHERE RecordID = me.RecordID
I actually thought I knew how to do this based on examples, however every time I try, then try to run on button click, I get a run-time error of SYNTAX error, and the debug just highlights the db.execute(sql) part. So I tried to get the resulting immediate window of the sql statement, and it looks fine to me:
UPDATE tblMain
SET [Name] = "John Doe",
[DATE] = #9/30/2009#,
[TYPE] = "TypeA",
WHERE RecordID = 958;
Can I update a table without accounting for every field in the table (because this one has about 15 plus the new 3, so I am ignoring about 14 fields here, but I do not want to alter those anyway???
So as always, I appreciate the help yall!! Thanks!
EDIT:
Sorry I always forget this....I was actaully trying it DAO....
Dim db as DAO.Database
Dim sql as String
set db = CurrentDb
etc
You were thaaat close! You have a simple extra comma after your last column. Get rid of it and it works fine.
UPDATE tblMain SET
[Name] = "John Doe",
[DATE] = #9/30/2009#,
[TYPE] = "TypeA"
WHERE RecordID = 958;
Yes, you can absolutely update only a few columns rather than all of them. That is a best practice, BTW.
Finally, It's considered bad practice to name your columns after reserved words like "Name" and "Date", but I know you inherited this.
You were wise to include Debug.Print sql in your code. bpayne already pointed out the extra comma in your SQL statement.
I want to point out another trouble shooting technique you may find useful to debug SQL statement problems.
Copy the statement from the Immediate Window, and paste it into the SQL View of a new query. Modify the query in the query designer until you can get it working, then revise your VBA code to generate a matching SQL statement.
In this case you might not have noticed the extra comma. However, you could create another new query and build the UPDATE statement from scratch in the query designer. After getting that one working, you could compare its SQL View to the failing query.