Paste Clipboard

K

Kathy Webster

OpenRecordset, and loop through the records.

Hmm, I know you've spent a lot of time already, but care to walk me through
trying this as a solution instead?
 
K

Kathy Webster

OpenRecordset, and loop through the records.
Hmm, I know you've spent a lot of time already, but care to walk me
through trying this as a solution instead?

Is that a resounding "no"?
 
K

Kathy Webster

Thank you Allen, no I never saw your reply. Will this work for a query as
well as a table? Would I just replace MyTable with MyQuery?
Then, how would I insert the looped field contents into the TO line of the
email?
 
A

Allen Browne

Give it a try, Kathy, and see.

(Or you could just use the name of the query as strSql.)
 
K

Kathy Webster

OK, sorry to be such a pest. I am the first one to admit my VB is less than
sketchy at best...
I pasted this into a module called EmailLup(), and my macro runs code
EmailLup().
This is what I pasted:

Function EmailLup()

'Purpose: How to open a recordset and loop through the records.
'Note: Requires a table named MyTable, with a field named MyField.
Dim rs As DAO.Recordset
Dim strSql As String

strSql = "SELECT Email FROM DA_EmailSL;"
Set rs = DBEngine(0)(0).OpenRecordset(strSql)

Do While Not rs.EOF
Debug.Print rs!Email
rs.MoveNext
Loop

rs.Close
Set rs = Nothing

DoCmd.SendObject acSendNoObject, , , rs

End Function

When I run it, I get: Compile error: User defined type not defined, and this
is highlighted in yellow:
rs As DAO.Recordset
 
D

Douglas J. Steele

You must be using either Access 2000 or 2002. In Access 97 and previous, DAO
(Data Access Objects) was the only way to communicate with the data. Around
the time Access 2000 was released, Access introduced another approach, ADO
(ActiveX Data Objects). For whatever perverse reasons, they decided not to
include DAO as a default libary.

With any code module open, select Tools | References from the menu bar,
scroll through the list of available references until you find the one for
Microsoft DAO 3.6 Object Library, and select it. If you're not going to be
using ADO, uncheck the reference to Microsoft ActiveX Data Objects 2.1
Library

If you have both references, you'll find that you'll need to "disambiguate"
certain declarations, because objects with the same names exist in the 2
models. For example, to ensure that you get a DAO recordset, you'll need to
use Dim rsCurr as DAO.Recordset (to guarantee an ADO recordset, you'd use
Dim rsCurr As ADODB.Recordset)

The list of objects with the same names in the 2 models is Connection,
Error, Errors, Field, Fields, Parameter, Parameters, Property, Properties
and Recordset
 
K

Kathy Webster

Wow. More stuff in the "over-my-head" category. Yes, I'm using Access XP
(2002)
You stated:
If you're not going to be using ADO...

How do I know if I'm using ADO?
 
D

Douglas J. Steele

You could either assume that you are using ADO, and just make sure that you
disambiguate all of the DAO stuff (since the reference to ADO is higher in
the list of references, it takes precedence, so ambiguous declarations will
actually default to ADO), or you could remove the reference and try
compiling your application (under the Debug menu when you're in the VB
Editor). If the application compiles, you don't need the reference. If the
application doesn't compile, add the reference back in.
 
K

Kathy Webster

OK. Did that. Added reference to Microsoft DAO 3.6 Object Library, Removed
reference to Microsoft ActiveX Data Objects 2.1 Library. It compiled.

Now when I run the code, I get:
Runtime error: 3061
Too few parameters. Expected 2.
....and this is in yellow:
Set rs = DBEngine(0)(0).OpenRecordset(strSql)
 
D

Dory A. Lottner

Kathy Webster said:
I have text in my clipboard from an MSAccess table. How can I paste it into
the TO line of my email? My users could be using one of many email
programs, so I am getting to their email program using MSAccess's
SendObject command. The cursor is now in the user's email TO line, with
the clipboard full of email addresses. How do I simply paste the text?

TIA,
Kathy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top