我有一张155K的记录表.我只能在带有query或sql记录源的表单的组合框中滚动65K记录,从该表中选择三个字段.为什么它不列出所有155K记录,即使是我用作记录源的查询,也会显示表单之外的所有记录.
也许项索引是一个16位整数
一个更好的问题是,你真的希望用户在组合框中滚动155,000个项目吗?
最简单的方法是只在您输入组合框中的某些字符后才分配组合框的Rowsource.你可以在组合框的OnChange事件中这样做:
Dim strRowSource As String strRowSource = "SELECT MyID, MyField FROM MyTable" If Len(Me!cmbMyCombo.Text)=3 Then strRowSource = strRowSource & " WHERE MyField Like '" strRowSource = strRowSource & Me!cmbMyCombo.Text strRowSource = strRowSource & "*'" Me!cmbMyCombo.RowSource = strRowSource Me!cmbMyCombo.DropDown End If
当您键入组合框时,在您键入3个字符(或2或4或任何适合将您的下拉列表过滤到人类可用的记录数)之前没有任何反应,此时会分配行源(并且,如果您愿意,可以在此时下拉列表,以使其更加用户友好).从那时起,它将像任何普通的组合框一样工作.
如果您需要使用相同的组合框来显示未输入的记录中的数据,那么您可以使组合框的默认Rowsource为:
PARAMETERS [Forms]![MyForm]![MyField] Text ( 255 ); SELECT MyID, MyField FROM MyTable WHERE MyField = [Forms]![MyForm]![MyField];"
然后在你的OnChange事件中,你会这样做:
Dim strRowSource As String strRowSource = "PARAMETERS [Forms]![MyForm]![MyField] Long; " strRowSource = strRowSource & "SELECT MyID, MyField FROM MyTable " strRowSource = strRowSource & "WHERE MyField = [Forms]![MyForm]![MyID]" strRowSource = strRowSource & "UNION SELECT MyID, MyField FROM MyTable" If Len(Me!cmbMyCombo.Text)=3 Then strRowSource = strRowSource & " WHERE MyField Like '" strRowSource = strRowSource & Me!cmbMyCombo.Text strRowSource = strRowSource & "*'" Me!cmbMyCombo.RowSource = strRowSource Me!cmbMyCombo.DropDown End If
然后在表单的OnCurrent事件中,你会这样做:
Dim strRowSource As String strRowSource = "PARAMETERS [Forms]![MyForm]![MyField] Text ( 255 ); " strRowSource = strRowSource & "SELECT MyID, MyField FROM MyTable " strRowSource = strRowSource & "WHERE MyField = [Forms]![MyForm]![MyField]" Me!cmbMyCombo.RowSource = strRowSource
这样做的目的是确保仍然显示已经分配给组合框所绑定字段的任何值.如果你有一个空白的RowSource,那将无法工作,所以对该表单的当前值的引用和对带有筛选列表的UNION它的引用.