简体   繁体   中英

How to use a combo box to fill mutltiple field in a subform in MS-Access?

I have a sub form in Access that allows a user to select records using check boxes. In addition to this sub form there is a combo box with a list of names.

Is it possible to select a few records using the check boxes and assign a name to them with a press of a button?

The button is called [assignButton] , the sub form is called [list subform] and the combo box is called [personCombo] .

This seems like a simple task, but I am unfamiliar with how the VBA for the button triggering this kind of action would be written?

这是我的表格的一个例子

All records are bound to an existing table called "tbl_jobs" this table has the same amount of rows and columns as the subform in the screenshot

Disclaimer : The following code is only intended to illustrate how to update the subform rows, so it includes no error handling or other common process code. Also notice that the SQL statement has no additional criteria in the WHERE clause, primarily because the question lacks the subform's actual RecordSource query and/or information about how the subform table is prepared and/or filtered for each time the form is loaded.

Private Sub AssignPerson_Click()
  Dim qry as QueryDef
  Set qry = CurrentDb.CreateQueryDef("", _
    "UPDATE tbl_jobs SET Person_Name = [ParamName]" & _
    " WHERE [Select] = True")
  qry.Parameters("ParamName") = PersonCombo.Value
  qry.Execute

  Me.list_subform.Requery 'Ensure subform displays updated rows
End Sub

Really this question is borderline "Too broad" for Stackoverflow. There are multiple ways to accomplish what you want, and your problem is one of design, coding and understanding. But in the end, this model code is rather simple and satisfies the basic requirements so I feel it not worth nitpicking.

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