Steve - Be sure to edit the file path, field names, table names. Once you decide if this is the route you want to go we can expand the routine so the user can select the path and file name from a dialog box.
-Bill
---In MS_Access_Professionals@yahoogroups.com, <thaw5@suddenlink.net> wrote :
---In MS_Access_Professionals@yahoogroups.com, <thaw5@suddenlink.net> wrote :
Thank you Bill. I'll try that in the next few days.
Steve
Steve
On 5/22/2018 3:35 PM, wrmosca@comcast.net [MS_Access_Professionals] wrote:
Steve - Here is a simple example. While in design view, Put a button named cmdWriteRecord on the form. Select the button and press F7. That will open the VBA editor to the button's click event. Paste in my code. Change the strSQL string to match your table and field names.
Private Sub cmdWriteRecord_Click()Dim strFile As StringDim db As DAO.DatabaseDim rs As DAO.RecordsetDim strSQL As StringDim strRec As StringSet db = CurrentDb'Get record from table that matches record on formstrSQL = "SELECT FirstName, LastName, Company " _& "FROM Customers WHERE ID = " & Me.IDSet rs = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)'Concatenate all fields into one stringstrRec = rs!FirstName & ", " & rs!LastName & ", " & rs!Company'Open text file. Create if it doesn't exist.strFile = "U:\_HOLD\myTextFile.txt"'Open file for appendingOpen strFile For Append As #1'Write our string to the fileWrite #1, strRec'Clean up pointersClose #1Set rs = NothingSet db = NothingEnd Sub-Bill
---In MS_Access_Professionals@yahoogroups.com, <wrmosca@comcast.net> wrote :
Steve - I didn't forget about you. Just ran out of time. My plan is to use a query on the same source as your form and have the WHERE clause use the same ID as the current row in the form.Then concatenate the fields into one string and write that string to a text file.
__._,_.___
Posted by: wrmosca@comcast.net
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (9) |
Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.
.
__,_._,___
Tidak ada komentar:
Posting Komentar