What's wrong with the syntax of this?

F

Fred

I think that I should treat this like a new question

I posed the below quesion and Paolo was kind enough to provide the below
answer. (Thank you!)

But when I tried it it errored out, saying that there is a syntax error in
the following line:

Set rec_mail = CurrentDb.OpenRecordset("select * from people",
dbopendynaset)

Could you tell me what is wrong / how to fix it?

Thank you very much.


Fred



Hi Fred,
if I've understood well your question create a button and add this code to
the on click event

Dim rec_mail As DAO.Recordset
Dim str_mail As String * 32000

Set rec_mail = CurrentDb.OpenRecordset("select * from people",
dbopendynaset)
tmp_mail = ""
Do While Not rec_mail.EOF
tmp_mail = tmp_mail & rec_mail!emailaddress & ","
rec_mail.MoveNext
Loop
str_mail = Left(Left(tmp_mail, Len(tmp_mail) - 1) & Space(32000), 32000)
file_num = FreeFile
Open "c:\email.txt" For Random As #file_num Len = 32000
Put #file_num, , str_mail
Close #file_num
rec_mail.close

HTH Paolo
 
D

Dirk Goldgar

Fred said:
I think that I should treat this like a new question

I posed the below quesion and Paolo was kind enough to provide the below
answer. (Thank you!)

But when I tried it it errored out, saying that there is a syntax error in
the following line:

Set rec_mail = CurrentDb.OpenRecordset("select * from people",
dbopendynaset)

Could you tell me what is wrong / how to fix it?


First, do you have a reference set to the "Microsoft DAO 3.6 Object Library"
(if you're using Access 95 to 2003) or the "Microsoft Office 12.0 Access
database engine Object Library" (if you're using Access 2007)? These
references are specified in the Tools -> References... dialog accessible
from the VB Editor's menu bar.

Second, was your statement originally broken onto two lines like that? I
don't see any line-continuation character. If you want to break the
statement onto two lines, you need to use the line-continuation character
"_", like this:

Set rec_mail = CurrentDb.OpenRecordset( _
"select * from people", dbOpenDynaset)
 
F

Fred

Dirk,

Thank you sooooo much for responding.


I gave you verbatim what I tried. So I'll try the continuation character,
especially since it said syntax error.

If not I'll need to to workign on finding the VB editor and it's menu bar
to try your other suggestions.

Thanks again

Fred
 
D

Dirk Goldgar

Fred said:
I gave you verbatim what I tried. So I'll try the continuation
character,
especially since it said syntax error.

If not I'll need to to workign on finding the VB editor and it's menu bar
to try your other suggestions.


And did either approach work? Inquiring minds want to know.
 
F

Fred

Hello Dirk,

(using 2003)

I tried just using the continuation character and it wouldn't let me put in
it ("complie error - invalid character")

So then I just put the whole statement into one line and it worked fine.

Then I went back and put in the continuation character in the exact manner
and place that you did.

When I find the "Access code for beginners" book that I have so far been
unable to find, I'll have to learn the rules for using the continuation
character.

Thanks again.

Fred
 

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