View Single Post
Old 08-24-2018, 03:15 AM   #3
isladogs
High Noon Moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 11,011
Thanks: 114
Thanked 3,014 Times in 2,741 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: SendKeys from form and loop trough records

Agree with Minty - don't use SendKeys. Slow & utterly unreliable

Here is a simple approach which will create a new text file & populate it or append text to an existing text file

Place this code in a standard module

Code:
Option Compare Database
Option Explicit

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim objFso As Object
Dim logStream As Object
Dim fs As Object

'######################################
'#  Use this to create and append a text file with log entries
'#
'#  Parameters
'#      strLogEntry text to write eg "Hello world!"
'#  Usage
'#      LogEntry " Hello World!"
'#
'#  This will create or add to a file with: Hello World!
'#
'######################################
Sub LogEntry(strLogEntry As String)
  
    AddTextToFile "Full path to text file", strLogEntry
   'e.g. AddTextToFile "c:\TestFiles\Text.txt", strLogEntry
    'Debug.Print strLogEntry
End Sub

Sub AddTextToFile(strLogFile As String, strLogEntry As String)

'Identical to WriteToFile but without the date/time
    On Error Resume Next
    
    Set objFso = CreateObject("Scripting.FileSystemObject")
    Set logStream = objFso.OpenTextFile(strLogFile, ForAppending, True) 'Open log file
    
    logStream.writeline strLogEntry
    
    logStream.Close
End Sub
Example usage:
AddTextToFile CurrentProject.Path & "\test.txt", "Hello World"

You can also enter the path in LogEntry and save repeated typing
LogEntry "Goodbye"

Each entry will be added to a new line



If you wish, the current time can be added to each new line
Attached Images
File Type: png Capture.PNG (3.2 KB, 137 views)

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin (Mendip Data Systems)
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


"As we know, there are known knowns; there are things we know we know. We also know there are known unknowns; that is to say we know there are some things we do not know. But there are also unknown unknowns the ones we don't know we don't know. It is the latter category that tend to be the difficult ones" Donald Rumsfeld
isladogs is offline   Reply With Quote
The Following User Says Thank You to isladogs For This Useful Post:
MushroomKing (08-24-2018)