在 VBA 中读取 RecordSet

发布于 2024-12-17 13:10:28 字数 435 浏览 4 评论 0原文

我正在使用 MS ACCESS 2010,

我有一个表,其中员工 ID 和其他一些字段存储为

f123 - - -
f543 - - -
f654 - - -
f123 - - -

等。

'当我运行时,

strSQL="Select Distinct emp_id from Tbl"

Set rs = db.OpenRecordset(strSQL)
rs.MoveFirst

Do While Not rs.EOF
    idVar = rs!Emp_Id
    rs.MoveNext
Loop

记录集中获得的值是 123、543 等,而不是 <强>f123、f543等 当我在查询设计视图中运行查询时,它工作得很好。请帮忙。

I'm working on MS ACCESS 2010

I have a table in which employee id's and some other fields are stored as

f123 - - -
f543 - - -
f654 - - -
f123 - - -

etc.

'when i run

strSQL="Select Distinct emp_id from Tbl"

Set rs = db.OpenRecordset(strSQL)
rs.MoveFirst

Do While Not rs.EOF
    idVar = rs!Emp_Id
    rs.MoveNext
Loop

The values obtained in recordset are 123, 543 etc. instead of f123, f543 etc.
When i run the query in query design view it works perfectly. Pls help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剧终人散尽 2024-12-24 13:10:28

上面的代码不运行。下面的代码运行 - msgbox 包含用于测试值

Private Sub Command0_Click()
Dim strSQL As String
Dim rs As Recordset
Dim idVar As String

strSQL = "Select Distinct emp_id from Tbl"

Set rs = CurrentDb.OpenRecordset(strSQL)
rs.MoveFirst

Do While Not rs.EOF
    idVar = rs!Emp_Id
    MsgBox idVar 'check value
    rs.MoveNext
Loop
End Sub

Code above doesnt run. Code below runs - msgbox included to test values

Private Sub Command0_Click()
Dim strSQL As String
Dim rs As Recordset
Dim idVar As String

strSQL = "Select Distinct emp_id from Tbl"

Set rs = CurrentDb.OpenRecordset(strSQL)
rs.MoveFirst

Do While Not rs.EOF
    idVar = rs!Emp_Id
    MsgBox idVar 'check value
    rs.MoveNext
Loop
End Sub
甜心小果奶 2024-12-24 13:10:28

我已经尝试重现这个问题,但恐怕没有成功。

请参阅屏幕转储。不确定这是否会对您有帮助。

谢谢马克
在调试模式下运行的代码的屏幕转储

I have tried to recreate the problem without any success I'm afraid.

Please see screen dump. Not sure if this is going to help you though.

Thanks Mark
Screen dump of code running in debug mode

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文