尝试在组合框中选择第一项时出现问题:VBA MS Access

时间:2017-01-28 20:39:51

标签: vba ms-access

我有以下代码来填充Combobox

StrSQL = "Select BankID, BankName As [Please Select Bank] from tblBank"
With Me.cmbBankSearch
  .RowSource = StrSQL
  .ColumnCount = 2
  .BoundColumn = 1
  .ColumnWidths = "0in.;1in."
  .ColumnHeads = True
  .LimitToList = True
  .Requery
  .Value = "Please Select Bank"
End With

但由于某些原因,我无法选择第一项是"请选择Bank"

我做错了吗?

根据下面的评论,我将其更改为以下代码。

StrSQL = "Select 0 as BankID, 'Please Select Bank' As [Please Select Bank] from tblBank UNION Select BankID, BankName As [Please Select Bank] from tblBank"

With Me.cmbBank
  .RowSource = StrSQL
  .ColumnCount = 2
  .BoundColumn = 1
  .ColumnWidths = "0in.;1in."
  .ColumnHeads = True
  .LimitToList = True
  .Requery
End With

1 个答案:

答案 0 :(得分:-1)

这应该足够了(来自combo / listboxes的值总是字符串):

StrSQL = "Select BankID, BankName As [Please Select Bank] from tblBank"
With Me.cmbBankSearch
  .RowSource = StrSQL
  .ColumnCount = 2
  .BoundColumn = 1
  .ColumnWidths = "0in.;1in."
  .ColumnHeads = True
  .LimitToList = True
  .Value = "0"
End With

编辑 - 没有列标题:

With Me.cmbBankSearch
  .RowSource = StrSQL
  .ColumnCount = 2
  .BoundColumn = 1
  .ColumnWidths = "0in.;1in."
  .ColumnHeads = False
  .LimitToList = True
  .Value = "0"
End With