Ciao Ragzzi,
Sto utilizzando il codice che posto sotto per prelevare dei dati da access e pubblcarli nei campi di un file word ora; il problema è il seguente: come potete notare il codice preleva da dei campi dalla maschera aperta ma come faccio a fargli prelevare i dati di una query su un dato campo?
Private Sub Comando63_Click()
'Written by Helen Feddema 4-22-98
'Last modified 7-Aug-2007
On Error GoTo ErrorHandler
Dim appWord As Word.Application
Dim docs As Word.Documents
Dim strLetter As String
Dim prps As Object
Dim strDate As String
Dim fso As New Scripting.FileSystemObject
Dim fil As Scripting.File
Dim strTemplate As String
Dim strTemplatePath As String
Dim strTemplateNameAndPath As String
Dim doc As Word.Document
Dim strTitle As String
Dim strPrompt As String
strDate = CStr(Date)
'Check whether template is found in the folder
'Get User Templates path from Word Options dialog
'(or replace with hard-coded path for your computer)
Set appWord = GetObject(, "Word.Application")
strTemplatePath = "C:\Documents and Settings\FDRDRA77R21G856K\Desktop\MISSIONI"
Debug.Print "Template path: " & strTemplatePath
strTemplatePath = strTemplatePath & "\FORMS\"
strLetter = "fuoriOrario.dotx"
strTemplateNameAndPath = strTemplatePath & strLetter
Debug.Print "Template and path: " & strTemplateNameAndPath
On Error Resume Next
Set fil = fso.GetFile(strTemplateNameAndPath)
If fil Is Nothing Then
strPrompt = "Can't find " & strLetter & " in " _
& strTemplatePath & "; canceling"
MsgBox strPrompt, vbCritical + vbOKOnly
GoTo ErrorHandlerExit
End If
On Error GoTo ErrorHandler
Set docs = appWord.Documents
Set doc = docs.Add(strTemplateNameAndPath)
Set prps = doc.CustomDocumentProperties
With prps
.Item("TodayDate").Value = Nz(Me![DATA_ATTIVITA])
.Item("Name").Value = Nz(Me![NOME])
.Item("Address").Value = Nz(Me![COMUNE_SITO_ATTIVITA])
.Item("CompanyName").Value = Nz(Me![RAGIONE_SOCIALE_DITTA])
'.Item("StateProv").Value = Nz(Me![ORA_FINE])
.Item("PostalCode").Value = Nz(Me![ORA_INIZIO])
'.Item("Salutation").Value = Nz(Me![ORA_INIZIO_PAUSA])
'.Item("JobTitle").Value = Nz(Me![ORA_FINE_PAUSA])
End With
With appWord
.Visible = True
.Activate
.Selection.WholeStory
.Selection.Fields.Update
.Selection.MoveDown Unit:=wdLine, Count:=1
End With
ErrorHandlerExit:
Exit Sub
ErrorHandler:
If Err = 429 Then
'Word is not running; open Word with CreateObject
Set appWord = CreateObject("Word.Application")
Resume Next
Else
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End If
End Sub