We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Access 2007 - vb code

Medium Priority
236 Views
Last Modified: 2012-05-11
my OS is windows 7 and I use Access 2007, can a guru plese debug the attached code as it is bombing at
Open CurrentProject.Path & "\EmailList.txt" For Output
At the directory, I have deleted the old Emaillist.txt files, so as to make life easier.
thank u
Private Sub mailemailreport_Click()
Dim rst As DAO.Recordset
Dim strDistList As String
Set rst = CurrentDb.OpenRecordset("Seniors Club")


Do While Not rst.EOF
    strDistList = strDistList & rst!Email & ";"
    rst.MoveNext
Loop
If MsgBox("Print Email distribution list to file?", vbYesNo, "Print?") = vbYes Then
  Dim lFile As Long
  '/get the next available File handle
  lFile = FreeFileHandle
  '/delete the file if it exists
  If Dir(CurrentProject.Path & "\EmailList.txt") <> "" Then Kill CurrentProject.Path & "\EmailList.txt"
  '/Now open the file
  Open CurrentProject.Path & "\EmailList.txt" For Output As #lFile
  '/write to that file
  Print #lFile, strDistList
  '/now close the file
  Close #lFile
Else
    strDistList = Left(strDistList, Len(strDistList) - 1)

    Me.Text46 = strDistList
End If

    

rst.Close
Set rst = Nothing

End Sub

Open in new window

Comment
Watch Question

Author

Commented:
Sorry to add the following o the above, at the following line what is the syntax to add a CR after each email.
strDistList = strDistList & rst!Email & ";"

thank u.
CERTIFIED EXPERT
Top Expert 2016
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
CERTIFIED EXPERT
Top Expert 2011
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
thank u both, it worked.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.