Hi Clifford, here it is:
The code for the log file is very simple:
*********************************************************
************Log file creation***************************
....
Set fs = CreateObject("Scripting.FileSystemObject")
Set logfile = fs.CreateTextFile("C:\My Documents\Report.log", True)
logfile.writeline ("Start of log file")
....
logfile.writeline (rst![Field])
....
************Log file creation***************************************
*********************************************************
The clipboard code is not mine and I just show you the whole piece:
*********************************************************
************Text to clipboard*****************************************
'<------------------------text2clipboard and clipboard2text
declarations------
Declare Function abOpenClipboard Lib "User32" Alias "OpenClipboard"
(ByVal Hwnd As Long) As Long
Declare Function abCloseClipboard Lib "User32" Alias "CloseClipboard" ()
As Long
Declare Function abEmptyClipboard Lib "User32" Alias "EmptyClipboard" ()
As Long
Declare Function abIsClipboardFormatAvailable Lib "User32" Alias
"IsClipboardFormatAvailable" (ByVal wFormat As Long) As Long
Declare Function abSetClipboardData Lib "User32" Alias
"SetClipboardData" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Declare Function abGetClipboardData Lib "User32" Alias
"GetClipboardData" (ByVal wFormat As Long) As Long
Declare Function abGlobalAlloc Lib "Kernel32" Alias "GlobalAlloc" (ByVal
wFlags As Long, ByVal dwBytes As Long) As Long
Declare Function abGlobalLock Lib "Kernel32" Alias "GlobalLock" (ByVal
hMem As Long) As Long
Declare Function abGlobalUnlock Lib "Kernel32" Alias "GlobalUnlock"
(ByVal hMem As Long) As Boolean
Declare Function abLstrcpy Lib "Kernel32" Alias "lstrcpyA" (ByVal
lpString1 As Any, ByVal lpString2 As Any) As Long
Declare Function abGlobalFree Lib "Kernel32" Alias "GlobalFree" (ByVal
hMem As Long) As Long
Declare Function abGlobalSize Lib "Kernel32" Alias "GlobalSize" (ByVal
hMem As Long) As Long
Const GHND = &H42
Const CF_TEXT = 1
Const APINULL = 0
'-------------------------text2clipboard and clipboard2text
declarations----->
'<------------------------text2clipboard function----->
Function Text2Clipboard(szText As String)
Dim wLen As Integer
Dim hMemory As Long
Dim lpMemory As Long
Dim retval As Variant
Dim wFreeMemory As Boolean
' Get the length, including one extra for a CHR$(0) at the end.
wLen = Len(szText) + 1
szText = szText & Chr$(0)
hMemory = abGlobalAlloc(GHND, wLen + 1)
If hMemory = APINULL Then
MsgBox "Unable to allocate memory."
Exit Function
End If
wFreeMemory = True
lpMemory = abGlobalLock(hMemory)
If lpMemory = APINULL Then
MsgBox "Unable to lock memory."
GoTo T2CB_Free
End If
' Copy our string into the locked memory.
retval = abLstrcpy(lpMemory, szText)
' Don't send clipboard locked memory.
retval = abGlobalUnlock(hMemory)
If abOpenClipboard(0&) = APINULL Then
MsgBox "Unable to open Clipboard. Perhaps some other
application is using it."
GoTo T2CB_Free
End If
If abEmptyClipboard() = APINULL Then
MsgBox "Unable to empty the clipboard."
GoTo T2CB_Close
End If
If abSetClipboardData(CF_TEXT, hMemory) = APINULL Then
MsgBox "Unable to set the clipboard data."
GoTo T2CB_Close
End If
wFreeMemory = False
T2CB_Close:
If abCloseClipboard() = APINULL Then
MsgBox "Unable to close the Clipboard."
End If
If wFreeMemory Then GoTo T2CB_Free
Exit Function
T2CB_Free:
If abGlobalFree(hMemory) <> APINULL Then
MsgBox "Unable to free global memory."
End If
End Function
'-------------------------text2clipboard function----->
************Text to clipboard****************************************
*********************************************************
Thank you very much
Giorgos
Clifford said:
Hi Giorgos,
Also, what is your code for logging to a file? Are you making sure to
create the file as a Unicode file? Otherwise, it may be creating an ASCII
file, which would not handle the Unicode characters not in the ASCII range.
Clifford Bass
Georgios Liakopoulos said:
Hi Clifford and thank you.
Either I copy the string content to the system clipboard (using code)
and then I paste it (manually) somewhere in a Word document or I write
the string content in a txt log file (using code). Even worse, when the
string has '?'s it is not written to the log file but returns an error
message (Run-time error 5: invalid procedure call or argument). I have
tried mystring = StrConv(rst![field], vbUnicode) but this returns "V a l
u e o f F i e l d " instead "Value of field".
Giorgos