Selasa, 22 Mei 2018

Re: [MS_AccessPros] Re: Copy record to the Windows clipboard?

 

Bill,

Got it to work. Thanks very much!

Steve

On 5/22/2018 5:39 PM, wrmosca@comcast.net [MS_Access_Professionals] wrote:
 

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 :

Thank you Bill. I'll try that in the next few days.

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 String
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strSQL As String
    Dim strRec As String
    
    Set db = CurrentDb
    'Get record from table that matches record on form
    strSQL = "SELECT FirstName, LastName, Company " _
        & "FROM Customers WHERE ID = " & Me.ID
    Set rs = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
    'Concatenate all fields into one string
    strRec = rs!FirstName & ", " & rs!LastName & ", " & rs!Company
    
    'Open text file. Create if it doesn't exist.
    strFile = "U:\_HOLD\myTextFile.txt"
    
    'Open file for appending
    Open strFile For Append As #1
    
    'Write our string to the file
    Write #1, strRec
    
    'Clean up pointers
    Close #1
    
    Set rs = Nothing
    Set db = Nothing
    
End 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: Steve thaw5 <thaw5@suddenlink.net>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (10)

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