• Running word from Access (XP/2K)

    • This topic has 1 reply, 2 voices, and was last updated 22 years ago.
    Author
    Topic
    #387562

    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

    Viewing 0 reply threads
    Author
    Replies
    • #676906

      (Edited by HansV to activate URL – see Help 19 – and to remove superfluous line ends.)

      There isn’t a setting that will turn off the Encoding autodetect. Word 2000 tries to figure out what language and encoding used in the text files but it doesn’t speak G-codes or M-Functions smile

      You can’t turn off via code Encoding autodetect. There is a workaround though. You can use the Word macro in this article to set the encoding to a given encoding and then all text files opened will use it.
      WD2000: “File Conversion Encoding” Dialog Box Appears When You Open Text File

    Viewing 0 reply threads
    Reply To: Running word from Access (XP/2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: