A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Email Mail Merge



 
 
Thread Tools Display Modes
  #11  
Old July 2nd, 2009, 04:27 AM posted to microsoft.public.access
Arvin Meyer MVP
external usenet poster
 
Posts: 640
Default Email Mail Merge

If you notice, there's no error handling. Add an error handling procedure
that enumerates the error.

Did you look for the file in C:\Mailing, plus the date? Are you using a
computer with permissions to write to the root of the C: drive?
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"Confused" wrote in message
news
All I did was create a function by clicking on Insert and selecting the
radio
button for function. I named it FOO pasted it and it ended up looking like
yours. I don't think I created a module.

I couldn't get it to work, so I deleted the function and inserted the code
on a command button click. For some reason it doesn't seem to do
anything.
How do you think I should proceed? Much Thanks!

Here is my code:


Private Sub Command45_Click()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strBCC As String
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset("qryContactsQuery", dbOpenSnapshot)

With rst
If .RecordCount 0 Then
.MoveLast
.MoveFirst
End If
End With

For i = 1 To rst.RecordCount
If Len(rst!EmailAddress) 0 Then
strBCC = strBCC & rst!EmailAddress & ";"
End If
rst.MoveNext
Next i
strBCC = Left$(strBCC, Len(strBCC) - 1)

'Debug.Print strBCC

Open "C:\Mailing" & Format(Date, "mmddyy") & ".txt" For Append As #1

Print #1, strBCC

Close #1






End Sub


"Arvin Meyer MVP" wrote:

By any chance did you name the module the same as the function? If so
change
the name of either the function or better still the module.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"Confused" wrote in message
...
I'm logged off from work, but here is what I recall. I clicked on the
Code
buttton and selected new procedure. I then selected the radio button
for
Function. I pasted the code.

Then I put a command button on the form for it's on click event. I
typed
=FOO()

I'm sure I messed up something. It's been a roller coaster ride...
Thanks!

"Tom Wickerath" wrote:

Tried that and got Compile Error/ Syntax Error.

What error message did you receive?

If you typed "=Foo()" (without the quotes) into the Properties listing
for
the On Click event, this would not even get picked up as a compile
error
even
if it was incorrect. So, I'm a bit confused as to what is causing your
error.

Or, did you create an OnClick procedure like this?

Private Sub CommandButtonName_Click()
Foo
End Sub

So, did you enter this on the Property Sheet, or in a new procedure?


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________

"Confused" wrote:

Hi,

Tried that and got Compile Error/ Syntax Error.

"Tom Wickerath" wrote:

Hi Confused,

Try this: =Foo()


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________

"Confused" wrote:

I clicked new procedure, function and inserted the code,
changing
the Query
name and fields. I then put a command button on the form and
on
the On
Click Event I typed Foo.

It's not doing anything. So how do I reference the Function or
where should
I put the code?






  #12  
Old July 2nd, 2009, 08:06 PM posted to microsoft.public.access
Tom Wickerath
external usenet poster
 
Posts: 3,914
Default Email Mail Merge

Also, when you state "For some reason it doesn't seem to do anything", are
you saying that the code is not running at all, or that it runs okay but
isn't producing the desired result? To verify that the code is running, add
a temporary line of code just prior to the Exit label (after inserting
error-handling code), which will generate a message (Hello) if the function
runs to completion:


Option Compare Database
Option Explicit

Private Sub Command45_Click()
On Error GoTo ProcError

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strBCC As String
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset("qryContactsQuery", dbOpenSnapshot)

With rst
If .RecordCount 0 Then
.MoveLast
.MoveFirst
End If
End With

For i = 1 To rst.RecordCount
If Len(rst!EmailAddress) 0 Then
strBCC = strBCC & rst!EmailAddress & ";"
End If
rst.MoveNext
Next i
strBCC = Left$(strBCC, Len(strBCC) - 1)

'Debug.Print strBCC

Open "C:\Mailing" & Format(Date, "mmddyy") & ".txt" For Append As #1

Print #1, strBCC

Close #1

MsgBox "Hello!" '---------Temporary Message Box

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Command45_Click..."
Resume ExitProc

End Sub


By the way, I recommend giving your controls a more reasonable name before
adding any code behind the control. "Command45" is not exactly an intuitive
name.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________


"Arvin Meyer MVP" wrote:

If you notice, there's no error handling. Add an error handling procedure
that enumerates the error.

Did you look for the file in C:\Mailing, plus the date? Are you using a
computer with permissions to write to the root of the C: drive?
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"Confused" wrote in message
news
All I did was create a function by clicking on Insert and selecting the
radio
button for function. I named it FOO pasted it and it ended up looking like
yours. I don't think I created a module.

I couldn't get it to work, so I deleted the function and inserted the code
on a command button click. For some reason it doesn't seem to do
anything.
How do you think I should proceed? Much Thanks!

Here is my code:


Private Sub Command45_Click()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strBCC As String
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset("qryContactsQuery", dbOpenSnapshot)

With rst
If .RecordCount 0 Then
.MoveLast
.MoveFirst
End If
End With

For i = 1 To rst.RecordCount
If Len(rst!EmailAddress) 0 Then
strBCC = strBCC & rst!EmailAddress & ";"
End If
rst.MoveNext
Next i
strBCC = Left$(strBCC, Len(strBCC) - 1)

'Debug.Print strBCC

Open "C:\Mailing" & Format(Date, "mmddyy") & ".txt" For Append As #1

Print #1, strBCC

Close #1






End Sub


"Arvin Meyer MVP" wrote:

By any chance did you name the module the same as the function? If so
change
the name of either the function or better still the module.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"Confused" wrote in message
...
I'm logged off from work, but here is what I recall. I clicked on the
Code
buttton and selected new procedure. I then selected the radio button
for
Function. I pasted the code.

Then I put a command button on the form for it's on click event. I
typed
=FOO()

I'm sure I messed up something. It's been a roller coaster ride...
Thanks!

"Tom Wickerath" wrote:

Tried that and got Compile Error/ Syntax Error.

What error message did you receive?

If you typed "=Foo()" (without the quotes) into the Properties listing
for
the On Click event, this would not even get picked up as a compile
error
even
if it was incorrect. So, I'm a bit confused as to what is causing your
error.

Or, did you create an OnClick procedure like this?

Private Sub CommandButtonName_Click()
Foo
End Sub

So, did you enter this on the Property Sheet, or in a new procedure?


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________

"Confused" wrote:

Hi,

Tried that and got Compile Error/ Syntax Error.

"Tom Wickerath" wrote:

Hi Confused,

Try this: =Foo()


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________

"Confused" wrote:

I clicked new procedure, function and inserted the code,
changing
the Query
name and fields. I then put a command button on the form and
on
the On
Click Event I typed Foo.

It's not doing anything. So how do I reference the Function or
where should
I put the code?






 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:49 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.