INSERT INTO table from form with checkboxes - sql

I would like to insert multiple entries into a table using a single form.
Desired outcome:
DESTINATION_TABLE
DATE | PLACE | THEME | PARTICIPANT
dd.mm.yyyy A X 1
dd.mm.yyyy A X 2
dd.mm.yyyy B Y 3
PLACE and PARTICIPANT are to be selected from values contained in other tables, while DATE and THEME are entered using text boxes. Only one value is to be inserted into the table at a time for DATE, PLACE and THEME, but I would like to be able to insert multiple PARTICIPANT, with a new row for each PARTICIPANT selected.
Adding new entries for DATE, PLACE and THEME via a form works (using CurrentDb.Execute "INSERT INTO...).
How can I create a form that would let me select PARTICIPANT from a subform (ideally with checkboxes) filtered from the value in PLACE, and add an entry in DESTINATION_TABLE for each PARTICIPANT selected ?

One simple way of doing it, with your current setup is to:
add a Yes/No field to your participants table, default to No. We'll call this field Selected
Bind your subform to the participants table, the user will be able to check each participant from this view(using the Selected field).
From which ever event you're using to save you data(e.g. Button Click), create a recordset(rs) based on the selected participants from the participants table(SELECT * FROM PARTICIPANT WHERE Selected = True. Loop through each record in the recordset(rs) and execute your code CurrentDb.Execute "INSERT INTO...), taking the value of the participant(rs("Participant")) from the recordset.
Once the loop is finished, update the participants table setting the Selected field to No. CurrentDb.Execute "UPDATE PARTICIPANT SET Selected = False WHERE Selected = True"
Refresh/Requery your sub form data if needed
Substitute above object names with yours.

Related

Access Form - Combo Box From Lookup Table, Updating Look Up Value Text to LookupID - No code telling it to

First time poster, long time Junior Varsity Access Developer
MS Access 2016 on Win 10 system (not connectable to public network)
I have form with a text field - Event Name (Pulled from existing value in Events table) and 3 unbound combo boxes (created from Wizard, select key field and lookup value text, hide key field, save value for later use) on a form that each pull values from a respective lookup table
Lookup table structure:
tblCategories: CategoryID (PK, Integer) | CategoryName (Text 255)
tblDirectorate: DirectorateID (PK, Integer) | DirectorateName (Text 255)
tblLocation: LocationID (PK, Integer) | LocationName (Text 255)
What should happen:
User completes the form, selects values from each of the combo boxes (Category, Directorate, Location) clicks Save Event button. (Tested - Values passed to SQL statement correspond to values from combo box)
Update SQL Statement runs, updates Events table and sets values in table to values on form (Update SQL Syntax correct, I did a debug.print to immediate window, copy and paste to QBE, run SQL, Update runs correctly)
What does happen:
User completes the form, selects values from each of the combo boxes (Category, Directorate, Location) clicks Save Event button. (Tested - Values passed to SQL statement correspond to values from combo box)
Update SQL Statement runs, updates Events table and sets values in table to values on form (Update SQL Syntax correct, I did a debug.print to immediate window, copy and paste to QBE, run SQL, Update runs correctly)
(Here's the part that I can't explain) The value of CategoryName in tblCategories updates to the value of CategoryID
a. I do not have cascade updates on any of the tables
b. Nowhere in ANY of the code in the entire DB is there a SQL statement to update tblCategories
c. Nowhere in any part of the DB is there a command to update the value of CategoryName in tblCategories
d. Neither the values of [tblDirectorate].[DirectorateName] nor [tblLocations].[LocationName] update to their corresponding ID field value.
I'm completely befuddled by this. I've deleted / recreated the combo box for the Category lookup, verified that the actions / properties for all 3 lookups are the same.
Has anyone previously experiences this, or can throw out some additional troubleshooting ideas?
Thanks!
Jordan

Access 2014 SQL update table value from unbound form

I am trying to update a value in a table from an unbound form. The user needs to choose the product name, enter a sales value and then the value updates the correct record in the table. At present I have:
UPDATE tblStock
SET tblStock.Sold = [Forms]![frmItemsSold]![Text3]
WHERE ((([tblStock]![ProductName]=[Forms]![frmItemsSold]![Combo1])));
The form is frmItemsSold and Combo1 on the form has the product name. Text3 on the form contains the sold value which should update the correct record in the Sold field in tblStock. At present my code doesn't work. Any ideas?

MS Access - Using one combobox to select a record and one combobox to edit a column in that record

I have the following two comboboxes:
The left combobox gets it's values from one table and the right one from a different table. How would I even go about making it so when you select a record from the left combobox, and a value from the right combobox, and you click the tick button, the ID of the record in the right combobox gets written to a column in the record that you selected in the left combobox.
Thank you!
Try executing something like this. (assuming your ID's are numeric, and you're running from the same form)
sql = "UPDATE leftTable SET rightID = " & me!rightboxID & " WHERE leftID = " & me!leftboxID

Dynamically Changing Value in APEX Based on Select List Selection

I currently have a select list with the values: 1, 2, 3, 4 & 5. These correspond to a column in table "DVD" called "DVDID", and these are the only values in this column in the table.
In the table "DVDCOPY" records exist containing the all DVDIDs (1,2,3,4,5) with a different DVDCOPYID.
E.g. a record from the DVDCOPY table is:
DVDCOPYID DVDID DISCCONDID
1 1 1
My question is, how can I make it so that once a DVDID is selected from the select list, the DVDCOPYID changes dynamically based on this selection? E.g. once 1 is selected in the DVDID select list, the value for DVDCOPYID also changes to 1 automatically.
My form currently looks like this, if this helps:
APEX Form
You have to use dynamic actions and PL/SQL. Create a hidden form element which allows for element changes (no session protection enabled). Create a new dynamic action in your form guiding to the select list and using the onchange event. Your dynamic action contains two steps: first set the hidden form element to the value of your select list. Second: execute a PL/SQL statement (UPDATE DVDCOPYID SET ... = :NEW_HIDDEN_ELEMENT WHERE ID = ...).

Text and value to combobox Excel VBA

I have two tables in Excel
First Table: Table Students: ID, last name, first name address and etc.
Table Two: Notes on the students: each student can have some records,i have two columns of this table. student ID and comments
The table I want to fill out a form
Will form a combo box with all the students and a text box for entering notes, the Add button will add the records
I wanted a combo box will appear the name of the student (last name+first name) and when they click Add, the code will put the ID student's of the selected student
I thought Combo Box can be set for each row: text and value, the text view and the value is not
As in ASP.NET
dropdownlist.datatextfield = Name
dropdownlist.datavaluefield = ID
Now I see only text can be set
Am I wrong and I can not well known, and if not how can I solve the problem
you have declare two combo box
one with the names and second with rhe id
the id's combo box there is disables
Order of the two combobox will be listed as the order in which it appears in the table
To get the ID of the selected student:
cbxId.List(cbxNames.ListIndex)
You can create a ComboBox with 2 columns - value and text.
In Excel, define the 2-column range and then use that as the rowsource for the control.
In the combobox properties, use BoundColumn = 1 and ColumnCount = 2, with the ColumnWidths values = 0pt; 20pt.
This mimicks the classic HTML 'select' control quite well I find, as you can simply call the Value from the control and as you've set the bound column to be the 'value' column, then it returns your ID for you quite easily.
combo box properties
results when cmd is clicked
raw data