ms-access:rowsource问题

时间:2009-12-22 22:33:40

标签: sql ms-access vba

我是一名vb.net程序员,我用excel做了很多VBA。我是访问的初学者。

有人给了我一个访问数据库来调试,我迷路了。

我成功地将它连接到本地mysql数据库。

我在表单上有一个列表框,该表单的行源附加到名为listbox的查询中。这是列表框属性的图片: alt text http://img192.imageshack.us/img192/936/listboxotherrelationsls.png

显示查询结果存在一些问题,因为查询过于复杂且结构不正确。当查询结果少于几个时,它们会在列表框中显示没有问题,但是当结果超过4-5时,它会将其留空;但是,我知道它返回了正确的数字,因为它留下了正确的行数(在列表框中为空)。因此,我不想尝试修复这个庞大的杂乱查询,而是想在字符串中提供所有行,然后将它们反馈到列表框中。

有人可以帮我吗?当你回复时,请把你的回答用外行的条款,因为我说我是一个访问初学者。

这是列表框在不想显示结果时的样子: alt text http://img43.imageshack.us/img43/4632/fullscreencapture122220.jpg

2 个答案:

答案 0 :(得分:1)

我想知道Column Count属性是否正确。那是查询中有十列还是字段?

你也应该在Column Widths属性中放入十个宽度,即使它们是0“宽度。我只看到七个宽度。

这是Access 2003与SP3?如果是这样,请参阅此KB article。安装Office 2003 Service Pack 3后,组合框控件和列表框控件在Access 2003中不显示任何值或不正确的值

答案 1 :(得分:1)

你可以在这些方面尝试一些事情:

''Some notes on declarations for ADO recpdset and connection
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection

''Set the connection object to the access project
''connection. You may wish to use a connection string (see below)
Set cn = CurrentProject.Connection

''Open the recordset, change the sql string to whatever string is used
''to populate the listbox
rs.Open "SELECT * FROM Testaccess", cn

''Convert the recordset to a string delimited by row and column with ;
''This is the delimiter needed by Access for the listbox with value data
strlist = rs.GetString(, , ";", ";")

''Set the rowsource of the listbox to the string
Me.List0.RowSource = strlist

''It would be easiest to set these before the run
''None of this is necessary, it can all be set as properties 
''of the listbox before the code is run
''Column count, same as number of fields
Me.List0.ColumnCount = rs.Fields.Count
''List type is values
Me.List0.RowSourceType = "Value List"

''This is just a set of 1cms for each column
For i = 1 To rs.Fields.Count
    strWidths = strWidths & ";1cm"
Next

''here we go, all columns set to 1cm width
Me.List0.ColumnWidths = Mid(strWidths, 2)

连接字符串:http://www.connectionstrings.com/

相关问题