?
Solved

Access 2007 - vb code

Posted on 2011-02-19
7
Medium Priority
?
481 Views
Last Modified: 2012-05-11
My OS is windows 7, and the code below was submitted by one of the Gurus.  I would like to modify it so that I will be asked if I want to export to a ASCII file or Just as the code is.  If the response yes to the first Question, then could u please write me the code to export to a file.
Thank u
Private Sub btnDistList_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

    strDistList = Left(strDistList, Len(strDistList) - 1)

    Me.txtDistList = strDistList

rst.Close
Set rst = Nothing
End Sub

Open in new window

0
Comment
Question by:jegajothy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 34932822
Export what?
There doesn't appear to be anything to export.
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 total points
ID: 34932931
You can use a MsgBox if you wish to "export" your strDistList variable:

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
End If


 
 
0
 
LVL 31

Assisted Solution

by:Helen Feddema
Helen Feddema earned 1000 total points
ID: 34933269
Why not just export the emails directly from the table that the recordset is based on, rather than constructing a string of them?
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 31

Expert Comment

by:Helen Feddema
ID: 34933283
Make a select query with just the email field, and then export it using TransferText:
DoCmd.TransferText transfertype:=acExportDelim, _
      tablename:="qryEmail", _
      FileName:="D:\Documents\Emails.csv", _
      hasfieldnames:=True

Open in new window

0
 

Author Comment

by:jegajothy
ID: 34935181
In response to LSM Consulting, when the code was executed I got a Run time error 52 and it says "Bad file name or number".
Maybe if we  also a define a path, like : C:\Documents, it will prevent the code from going crazy.
Hope u can fix the code.  Thank u for your response.
0
 

Author Comment

by:jegajothy
ID: 34935186
In response to Helen Fedema, sorry being a novice.  But can u please document your code.
What is tablename set to : Is it a query?
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 34969595
transfertype, tablename, FileName, and HasFieldNames are the arguments of the TransferText method.  I like to use named arguments, for greater clarity.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question