基本的DAO.Recordset问题 [英] Basic DAO.Recordset question

查看:95
本文介绍了基本的DAO.Recordset问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,这似乎不起作用...

我错过了一些基本的东西吗?


Dim rst作为DAO.Recordset

Dim db作为DAO.Database

设置db = CurrentDb

设置rst = db.OpenRecordset(" qryEmailS")''< = can我在这里使用查询?


''qryEmailS只包含一列 - strS

''我想循环遍历第一个中的每个项目br />
''我必须先在这里使用吗?怎么样的阵列?


直到rst.EOF

Debug.Print rst!strS

rst.MoveNext

循环

解决方案

" deko" < DJ **** @ hotmail.com>在留言中写道

news:5U **************** @ newssvr27.news.prodigy.com ...

For有些原因这似乎没有用......
我错过了一些基本的东西吗?

Dim rst作为DAO.Recordset
Dim db作为DAO.Database
设置db = CurrentDb
设置rst = db.OpenRecordset(" qryEmailS")''< =我可以在这里使用查询吗?

''qryEmailS只包含一列 - strS ;'
''我想循环遍历第一个中的每个项目
''我必须先在这里使用吗?怎么样的阵列?

直到rst.EOF
Debug.Print rst!strS
rst.MoveNext
Loop



这对我来说很好看。它在做什么(或不做)?你收到了

的错误吗?你有没有参考DAO套装?

-

我没有查看电子邮件帐户附上

来此消息。发送给...

在Hunter dot com的RBrandt


>它对我来说很好看。它在做什么(或不做)?您是否收到

错误?你有DAO集的参考吗?




我得到的错误是:


错误编号3061:参数太少。预期1.


这是qryEmailS:


SELECT tblEntity.FirstName as strS FROM tblEntity

WHERE(( tblEntity.Entity_ID)= Forms!frmMain!frm0.Form!Ent ity_ID)

AND tblEntity.FirstName不为空

UNION SELECT tblEntity.LastName FROM tblEntity

WHERE((tblEntity.Entity_ID)= Forms!frmMain!frm0.Form!Entity_ID)

AND tblEntity.LastName不为空

UNION SELECT tblEntity。公司FROM tblEntity

WHERE((tblEntity.Entity_ID)=表格!frmMain!frm0.Form!Entity_ID)

AND tblEntity.Company不是空的

UNION SELECT tblEmail.EmailAddress FROM tblEmail

WHERE((tblEmail.Entity_ID)= Forms!frmMain!frm0.Form!Enti ty_ID)

AND tblEmail.EmailAddress Is不是空的;


我想要做的很简单 - 我需要检查qryEmailS的任何

结果是否属于特定的字符串:


Dim rst作为DAO.Recordset

Dim db作为DAO.Database

设置db = CurrentDb

设置rst = db.OpenRecordset(" qryEmailS")


For每个olmi In olfsm.Items

Do until rst.EOF

If(InStr(olmi.To,rst!strS))> 0然后

''在这里做点什么

结束如果

rst.MoveNext

Loop

下一页


我需要一些方法来遍历查询中的每个项目,我在想

a记录集是要走的路,除非有某种方法可以获得查询

结果到一个数组。我想知道我是否收到运行时错误

因为查询是一个联合查询...


谢谢!


你的代码很好。如果您收到错误3061(参数太少。

预期1),查询需要一个参数(它很适合它),

或它有一个语法错误。打开查询所引用的表单,输入与之前使用的完全相同的值,然后手动运行查询(不是代码中的
)&走着瞧吧。我打赌它会爆炸!


HTH,

TC

" deko" < DJ **** @ hotmail.com>在留言中写道

news:5U **************** @ newssvr27.news.prodigy.com ...

For有些原因这似乎没有用......
我错过了一些基本的东西吗?

Dim rst作为DAO.Recordset
Dim db作为DAO.Database
设置db = CurrentDb
设置rst = db.OpenRecordset(" qryEmailS")''< =我可以在这里使用查询吗?

''qryEmailS只包含一列 - strS ;'
''我想循环遍历第一个中的每个项目
''我必须先在这里使用吗?怎么样的阵列?

直到rst.EOF
Debug.Print rst!strS
rst.MoveNext
Loop


For some reason this does not seem to be working...
Am I missing something basic?

Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
Set rst = db.OpenRecordset("qryEmailS") '' <= can I use query here?

'' qryEmailS contains only one column - "strS"
'' I want to loop through each item in the rst
'' must I use rst here? how about Array?

Do Until rst.EOF
Debug.Print rst!strS
rst.MoveNext
Loop

解决方案

"deko" <dj****@hotmail.com> wrote in message
news:5U****************@newssvr27.news.prodigy.com ...

For some reason this does not seem to be working...
Am I missing something basic?

Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
Set rst = db.OpenRecordset("qryEmailS") '' <= can I use query here?

'' qryEmailS contains only one column - "strS"
'' I want to loop through each item in the rst
'' must I use rst here? how about Array?

Do Until rst.EOF
Debug.Print rst!strS
rst.MoveNext
Loop



It looks good to me. What is it doing (or not doing)? Are you getting an
error? Do you have a reference to DAO set?
--
I don''t check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


> It looks good to me. What is it doing (or not doing)? Are you getting an

error? Do you have a reference to DAO set?



The error I''m getting is:

Error Number 3061: Too few parameters. Expected 1.

This is qryEmailS:

SELECT tblEntity.FirstName as strS FROM tblEntity
WHERE ((tblEntity.Entity_ID)=Forms!frmMain!frm0.Form!Ent ity_ID)
AND tblEntity.FirstName Is Not Null
UNION SELECT tblEntity.LastName FROM tblEntity
WHERE ((tblEntity.Entity_ID)=Forms!frmMain!frm0.Form!Ent ity_ID)
AND tblEntity.LastName Is Not Null
UNION SELECT tblEntity.Company FROM tblEntity
WHERE ((tblEntity.Entity_ID)=Forms!frmMain!frm0.Form!Ent ity_ID)
AND tblEntity.Company Is Not Null
UNION SELECT tblEmail.EmailAddress FROM tblEmail
WHERE ((tblEmail.Entity_ID)=Forms!frmMain!frm0.Form!Enti ty_ID)
AND tblEmail.EmailAddress Is Not Null;

What I''m trying to do is pretty simple - I need to check if any of the
results of qryEmailS are in a particular string:

Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
Set rst = db.OpenRecordset("qryEmailS")

For Each olmi In olfsm.Items
Do Until rst.EOF
If (InStr(olmi.To, rst!strS)) > 0 Then
''do something here
End If
rst.MoveNext
Loop
Next

I need some way to iterate through each item in the query, and I''m thinking
a recordset is the way to go, unless there is some way to get the query
results into an array. I''m wondering if I''m getting that runtime error
because the query is a union query...

Thanks!


Your code is fine. If you are getting error 3061 (Too few parameters.
Expected 1), the query requires a parameter (which it apparanetly doesn''t),
or it has a syntax error. Open the form to which the query refers, enter the
exact same values that you used before, then run the query manually (not
from code) & see what happens. I bet it blows up!

HTH,
TC
"deko" <dj****@hotmail.com> wrote in message
news:5U****************@newssvr27.news.prodigy.com ...

For some reason this does not seem to be working...
Am I missing something basic?

Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
Set rst = db.OpenRecordset("qryEmailS") '' <= can I use query here?

'' qryEmailS contains only one column - "strS"
'' I want to loop through each item in the rst
'' must I use rst here? how about Array?

Do Until rst.EOF
Debug.Print rst!strS
rst.MoveNext
Loop



这篇关于基本的DAO.Recordset问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆