Results 1 to 9 of 9
  1. #1
    Carlus is offline Novice
    Windows 10 Access 2021
    Join Date
    Oct 2023
    Posts
    4

    Compiling Word from Access from VBA - inserting images gives error

    Hi everyone,

    I have a little problem and I hope someone can help me.

    I created a sub using VBA in a form that upon click opens and compiles an existing Word document by replacing the Bookmarks present in the same Word.

    Among the replacements there are also images (signatures) that vary based on a combo box selection.

    Once the command is launched, the compilation begins correctly but stops (not always but once in three) on inserting images (signatures) with this error message: "Run Time Error 462 the path was not found"

    the statement I use is Selection.InlineShapes.AddPicture

    Below is part of the Sub code

    Let me start by saying that I am a novice with VBA

    thanks to anyone who wants to help me


    percorsoimmagini = "c:...\FileDatabase\Immagini"
    End Function

    Dim FirmaRL As String
    Dim idfirmaRL As String
    idfirmaRL = Txt_RL_ID
    FirmaRL = percorsoimmagini & idfirmaRL & ".png"
    Wrd.ActiveDocument.Bookmarks("FirmaRL1").Select
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False


    End With

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I don't see that line anywhere in the code supplied - please provide the full code and use copy/paste with the # button rather than an image.

  3. #3
    Carlus is offline Novice
    Windows 10 Access 2021
    Join Date
    Oct 2023
    Posts
    4
    Public Function percorsoimmagini() As String
    percorsoimmagini = "c:...\FileDatabase\Immagini"
    End Function

    Dim FirmaRL As String
    Dim idfirmaRL As String
    idfirmaRL = Txt_RL_ID
    FirmaRL = percorsoimmagini & idfirmaRL & ".png"
    Wrd.ActiveDocument.Bookmarks("FirmaRL1").Select
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.InlineShapes.AddPicture FileName:=FirmaRL, LinkToFile:=False, SaveWithDocument:=True

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Don’t see how that works - you are missing a procedure (or function) header and no end function

  5. #5
    Carlus is offline Novice
    Windows 10 Access 2021
    Join Date
    Oct 2023
    Posts
    4
    Hi,
    Code:
    Option Compare Database
    Option Explicit
    
    
    Public Function percorsodatabase() As String
    percorsodatabase = "\\192.158.1.38\Master Documenti\"
    End Function
    
    
    Public Function percorsoimmagini() As String
    percorsoimmagini = "\\192.158.1.38\Immagini\"
    End Function
    
    
    Private Sub CmdCreaDocTecnica_Click()
    
    
    Dim Wrd As Word.Application, Doc As Word.Document
    Dim rst As DAO.Recordset
    Dim Modello As String, NomeFile As String, i As Integer
    Dim Record As String, SQL As String
    Dim Tbl As String * 1
    Dim ReplSel As Boolean
    Dim stDocName As String
    Dim FirmaRL As String
    Dim idfirmaRL As String
    
    
    
    
        Modello = percorsodatabase & "DOCUMENTAZIONE.docx"
    
    
    
    
        On Error Resume Next
        Set Wrd = GetObject(, "Word.Application")
    If Err.Number = 429 Then
        Set Wrd = CreateObject("Word.Application")
    End If
        On Error GoTo 0
        Wrd.Visible = True
        Wrd.Activate
        ReplSel = Wrd.Options.ReplaceSelection
        Wrd.Options.ReplaceSelection = True
        Set Doc = Wrd.Documents.Add(Modello)
        Doc.Activate
    
    
    idfirmaRL = Txt_RL_ID
    FirmaRL = percorsoimmagini & idfirmaRL & ".png"
    
    
    Wrd.ActiveDocument.Bookmarks("FirmaRL1").Select
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.InlineShapes.AddPicture FileName:=FirmaRL, LinkToFile:=False, SaveWithDocument:=True
    
    
    DoCmd.RunCommand acCmdSaveRecord 'salva
    Wrd.Selection.HomeKey Unit:=wdStory 'torna con il cursore ad inizio documento
    'aggiorna sommario word
    
    
    
    
    If ActiveDocument.Fields.Update = 0 Then
    
    
    Else
        MsgBox "Field " & ActiveDocument.Fields.Update & "Esportazione bloccata, controlla i campi inseriti"
    End If
        Wrd.Application.WordBasic.MsgBox "Ottimo... Esportazione terminata!", "Esportazione dati da Access"
        
        Set Doc = Nothing
        Set Wrd = Nothing
    
    
    End Sub

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    thanks - what is the value of Txt_RL_ID? (use debug.print to verify it is what you think it is)

    and in line with the error message - can you confirm the file exists (replace somename with whatever value is
    Txt_RL_ID)

    \\192.158.1.38\Immagini\somename.png




  7. #7
    Carlus is offline Novice
    Windows 10 Access 2021
    Join Date
    Oct 2023
    Posts
    4
    HI
    the exact error text is this:
    Run-time error '462': The remote server computer does not exist or is unavailable.
    the file exists I tried, maybe sometimes it can't access the server?


    the exact error text is the same:Run-time error '462': The remote server computer does not exist or is unavailable.

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you haven't actually answered my questions. It may be your text field contains invalid characters or is incomplete in some way

    once you have debug printed the full path, copy it from the immediate window and paste it into windows explorer - does that work

  9. #9
    zpy2 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2023
    Posts
    4
    On Error Resume Next

    when you trouble shooting,please delete or comment above line to show specific wrong line.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-14-2014, 10:42 PM
  2. Inserting printable images in forms
    By Sash in forum Forms
    Replies: 1
    Last Post: 03-17-2014, 11:05 AM
  3. inserting records into word from access
    By sssandhya89 in forum Access
    Replies: 1
    Last Post: 03-22-2013, 11:33 AM
  4. Exporting Images to Word
    By GCS in forum Import/Export Data
    Replies: 3
    Last Post: 02-16-2012, 12:22 AM
  5. Replies: 0
    Last Post: 05-14-2009, 12:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums