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

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

Related

Replicate all column options for each entry

I'm fairly new to SQL and all I need to populate a table automatically where the values from column2 are always present for each value in column 1. For example, for every new item inserted on Column1(Names) I want a pre-defined set of values to populate Column2(Illnesses) I have no idea what to call this process and all my google searches returned nothing.
As an example:
When John is added to the Database it creates a row, I want to automatically duplicate John and fill column2 it with the following pre-defined options
I hope I'm explaining myself ok...probably I'm not so apologies.
You can use CROSS APPLY. Something like this:
SELECT [name], Illness
FROM
(
VALUES ('John')
) Names ([name])
CROSS APPLY
(
VALUES ('Flu')
,('Covid')
,('Common Cold')
,('Constipations')
,('Food Posoning')
) Illnesses(Illness)
You are showing a many-to-many data relationship which requires 3 tables. There should be a table of People and a table of Illnesses where in both each record is unique. Then a junction table PeopleIllnesses which should save PeopleID and IllnessID as foreign keys of the ID's from People and Illnesses.
You want to 'batch create' a set of records. Possibly need code in whatever app you are using to program interface (Access, vb.net, C#, etc). The new People record must first be committed to table. In VBA, code could be in click event of a button on data entry form for People and like:
Sub btnAddRecords_Click()
DoCmd.RunCommand acCmdSaveRecord
CurrentDb.Execute "INSERT INTO PeopleIllnesses(PeopleID, IllnessID) SELECT " & Me.tbxPID & ", IllnessID FROM Illnesses"
End Sub

INSERT INTO table from form with checkboxes

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.

MS Access: Passing Combo Box values from SQL

I've been stuck with this problem for a few days and can't figure it out. I have a small Access (2013) database that has a button on a form that writes the contents of some of the fields in the "Students" table to the related (child?) "Lunch" table. The Click event has the following line of code...
DoCmd.RunSQL "INSERT INTO Lunch (StudentID, DateOfLunch, TypeOfLunch, Cost) SELECT [ID],[TodaysDate],[TodaysLunch]![Column(1)],0 FROM Students"
This writes everything except the combobox value TodaysLunch into the [Students]![TypeOfLunch] combobox. I've tried [value][text], etc. but it's always blank. I have both of these combo boxes [TypeOfLunch][TodaysLunch] get their data from values from another table, if that means anything. Access throws no errors, there is just nothing in that field when I check it.
Try
DoCmd.RunSQL "INSERT INTO Lunch (StudentID, DateOfLunch, TypeOfLunch, Cost)
SELECT [ID],Forms![YourFormName]![TodaysDate],Forms![YourFormName]![TodaysLunch],0
FROM Students
Which will insert all student records into the lunch table with the selected lunch type & date from your form.

Sap B1 Quantity Field on Recommendation Form

I make some inserts on ORCM table by programmatically. Everything looks normal on database. Here is the insert query for ORCM table:
insert into ORCM (DocEntry,ObjAbs,ObjType,ItemCode,DueDate,OrderType,Quantity,UOM,CardCode,Warehouse,Price,Origin,Status,UserSign,DocDate,ReleasDate) values ("+mx+"," + objAbs +",199,'"+sale.itemCode+"',GETDATE(),'P',"+sale.quantity+",'','V10000','01',0,'M','O',1,GETDATE(),GETDATE())
But the quantity field on recommendation form is coming empty.
I couldn't find why this is happenning.

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