I have the following code which till today (of course when the program is supposed to be installed by the client) was working. Today the code stops after the text file is written and before word opens.
One problem is that the text file has Hebrew in it and when the text file opens in Word manually it asks you about changing the code page. Is there a way to programtically do that? Or does anyone have any other ideas?
Thanks
Private Sub Command28_Click()
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s
Dim x As Variant
Dim intSerial As Variant
Dim strRecord As String
Dim varLengTZ As Variant
Dim strPadTZ As String
Dim intRecCount As Integer
Dim strFileName As String
Dim blnMail As Boolean
Dim mobjWordApp As Word.Application
Dim strDirectory As String
strDirectory = fGetTableDir()
strFileName = strDirectory & “test1.txt”
Set fs = CreateObject(“Scripting.FileSystemObject”)
fs.CreateTextFile strFileName ‘Create a file
Set f = fs.GetFile(strFileName)
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
intSerial = 1 ‘ initialize intserial
intRecCount = Me.Recordset.RecordCount
DoCmd.GoToRecord , , acFirst
Do
IN HERE GOES A WHOLE BUNCH OF TEXT MANIPULATION FROM DATA ON A FORM
ts.Write strRecord
intSerial = intSerial + 1
intRecCount = intRecCount – 1
If intRecCount = 0 Then Exit Do
DoCmd.GoToRecord , , acNext
Loop Until intRecCount = 0
ts.Close
Set mobjWordApp = New Word.Application
With mobjWordApp
.Visible = True
.WindowState = wdWindowStateMaximize
.Documents.Open strFileName
.ActiveDocument.SaveAs FileName:=strFileName, FileFormat:=wdFormatText, _
LockComments:=False, Password:=””, AddToRecentFiles:=False, WritePassword _
:=””, ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=862, InsertLineBreaks:=False, AllowSubstitutions:=False, _
LineEnding:=wdCRLF, AddBiDiMarks:=False
.ActiveDocument.Close
End With
End
On Error GoTo 0
Exit Sub
End Sub