Results 1 to 2 of 2
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Running word from Access (XP/2K)

    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

  2. #2
    New Lounger
    Join Date
    May 2003
    Location
    Victoria, Br. Columbia, Canada
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running word from Access (XP/2K)

    (Edited by HansV to activate URL - see <!help=19>Help 19<!/help> - 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 <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •