开发者

Inserting multiple rows to table - Access

开发者 https://www.devze.com 2022-12-14 12:46 出处:网络
I have an Access application in which I need to do a \'mass-update\'. I have a form on which I have a dro开发者_Python百科pdown, a listbox, and a checkbox. I also have a Update button, and when the u

I have an Access application in which I need to do a 'mass-update'.

I have a form on which I have a dro开发者_Python百科pdown, a listbox, and a checkbox. I also have a Update button, and when the user clicks it, I want to insert rows into my table with the same value for the dropdown and checkbox fields in all the rows, but I want different values for each row depending on the list items that were selected.

I know that multiple rows can be inserted into a table using the UNION SELECT statement, but how am I supposed to apply that with a listbox?

Can anyone please help?

Thanks in Advance


You can create an update statement for each item selected. For example:

strSQLBase="INSERT INTO Table (Field1, Field2, Field3) Values (" & Me.Dropdown _
    & "," & Me.CheckBox & ","
For Each itm In Me.ComboBox.ItemsSelected
    strSQL = strSQLBase & Me.ComboBox.Column(0, itm) & ")"
    CurrentDb.Execute strSQL
Next
0

精彩评论

暂无评论...
验证码 换一张
取 消