Hi all. I have a form (with a table behind) where I put students data, included the picture of each one, uploaded as "attachment".
I have also a button that allow me to populate a word model file (.dotx) with those data through bookmarks. The only thing I can't manage to export is every related picture. This is the code I use to populate the Word model:
Code:
Private Sub schedallievo_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, strSQL As String
Dim Email1 As Hyperlink
Dim TotRiga As Integer, TOTALE As Integer
Dim ReplSel As Boolean
Modello = CurrentDb.Name
Modello = Left(Modello, Len(Modello) - Len(Dir(Modello))) & "schedallievo.dotx"
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
Doc.Bookmarks("Nome").Select
Wrd.Selection.Font.AllCaps = True
Wrd.Selection.TypeText Me.NOME
Doc.Bookmarks("Cognome").Select
Wrd.Selection.Font.AllCaps = True
Wrd.Selection.TypeText Me.COGNOME
Doc.Bookmarks("datanascita").Select
Wrd.Selection.Font.AllCaps = True
Wrd.Selection.TypeText Me.Data_di_nascita
Doc.Bookmarks("residenza").Select
Wrd.Selection.Font.AllCaps = True
Wrd.Selection.TypeText Me.INDIRIZZO
Doc.Bookmarks("tel").Select
Wrd.Selection.Font.AllCaps = True
Wrd.Selection.TypeText Me.Telefono1
Doc.Bookmarks("email").Select
Wrd.Selection.Font.AllCaps = True
Wrd.Selection.TypeText Me.Email1
Doc.Bookmarks("compartimento").Select
Wrd.Selection.Font.AllCaps = True
Wrd.Selection.TypeText Me.Compartimento
Doc.Bookmarks("matricola").Select
Wrd.Selection.Font.AllCaps = True
Wrd.Selection.TypeText Me.Matricola
Wrd.Application.WordBasic.MsgBox "Esportazione terminata", "Esportazione dati da Access"
End sub
The only missing thing is some instruction to export the picture too. I found that around in the net:
Code:
Selection.Goto What:=wdGoToBookmark, Name:="mypicture"
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:= _
"mypicturepath", _
LinkToFile:=False, SaveWithDocument:=True
That would work great if I could refer to a single file-picture stored somewhere. But in my case the picture is uploaded in the original table as attachment and shown in the form. I can't manage to find a modification that could work changing the "mypicturepath" with a Me.
Another soultion would be to collect all the pictures in a folder and refer to them, but how can I tell Access to link a single picture to an Id, and then export that related one to word?
Thanks in advance for advising.
Davide