1

ASP.NET では、データ ソースから CheckBoxList コントロールを構築するオプションがあります。項目の値は "Id" 列 (たとえば) であり、チェックボックスの横に表示されるテキストは "Name" 列からのものです。

VBA を使用して Access 2003 でこれと同様のことを行うことは可能ですか? 可能な限りアイテムのリストをハードコーディングすることは避けようとしていますが、これと同様のことを行う方法がわかりません。

4

1 に答える 1

2

Just use a listbox. A list box in Access is great because it allows multiple columns, but will hide the first column as you ask. And you can just set the listbox to allow multiple selections (in the other tab of the property sheet for the listbox, set Multiselect to "simple"

And even better is you don't need any code to fill out the listbox, but can type in the sql or simply base the listbox on a SQL query.

So a listbox can look like this:

enter image description here

The code behind the button to turn the selected items into a useful list of PK id looks like this:

Private Sub cmdFax_Click()

  Dim strIDList     As String
  Dim vID           As Variant
  Dim strSQLWhere   As String

  For Each vID In Me.lstFaxList.ItemsSelected

     If strIDList <> "" Then strIDList = strIDList & ","

     strIDList = strIDList & lstFaxList.ItemData(vID)

  Next

  If strIDList <> "" Then
     strSQLWhere = " ID in (" & strIDList & ")"
  End If

  DoCmd.OpenReport "rptFax", acViewPreview, , strSQLWhere


End Sub

And if you want, you can in code for supply or set the SQL of the listbox like this:

Sub mytest()

   Dim strSql        As String

   strSql = "Select ID, firstName, LastName, City " & _
            "where city = 'Edmonton'"

   Me.lstFaxList.RowSource = strSql


End Sub

So you don't need to type in any kind of list here. It not clear if you "must" have a actual check box here - you can use a continues form if you wanted, but I think the above is oh so much more simple and you don't need much code to set this up at all.

于 2012-08-18T16:46:24.447 に答える