简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM