Ciao, non sono programmatore, ma sto facendo un database dal quale devo stampare dei certificati con word. Uso i bookmarks e ho un problema con un documento che supera il limite dei 20 indici di VB. Come posso aggirare l'ostacolo?
Grazie.
Allego codice di access:
Private Sub M02_batt_Click()
Dim objWord As Word.Application
'Start Microsoft Word 2007.
Set objWord = CreateObject("Word.Application")
On Error Resume Next 'gestione errori step by step
'cerca un'istanza di Word già aperta
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
'se c'è stato un errore è perchè Word non era già aperto:
'aprilo adesso
Set objWord = CreateObject("Word.Application")
End If
With objWord
'Make the application visible.
.Visible = True
objWord.Activate
On Error GoTo M02_batt_Err
'Open the document.
.Documents.Open ("C:\parrocchia\moduli\M02_certificato_battesimo.doc")
'Move to each bookmark and insert text from the form.
If Forms!m_bb_anaview!SESSO = "M" Then
.ActiveDocument.Bookmarks("ao1").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!mas))
End If
If Forms!m_bb_anaview!SESSO = "F" Then
.ActiveDocument.Bookmarks("ao1").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!fem))
End If
If Forms!m_bb_anaview!SESSO = "M" Then
.ActiveDocument.Bookmarks("ao2").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!mas))
End If
If Forms!m_bb_anaview!SESSO = "F" Then
.ActiveDocument.Bookmarks("ao2").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!fem))
End If
If Forms!m_bb_anaview!SESSO = "M" Then
.ActiveDocument.Bookmarks("ao3").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!mas))
End If
If Forms!m_bb_anaview!SESSO = "F" Then
.ActiveDocument.Bookmarks("ao3").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!fem))
End If
If Forms!m_bb_anaview!SESSO = "M" Then
.ActiveDocument.Bookmarks("ao4").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!mas))
End If
If Forms!m_bb_anaview!SESSO = "F" Then
.ActiveDocument.Bookmarks("ao4").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!fem))
End If
If Forms!m_bb_anaview!SESSO = "M" Then
.ActiveDocument.Bookmarks("ao5").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!mas))
End If
If Forms!m_bb_anaview!SESSO = "F" Then
.ActiveDocument.Bookmarks("ao5").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!fem))
End If
.ActiveDocument.Bookmarks("vol").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!VOLUMEREGBATTESIMO))
.ActiveDocument.Bookmarks("pag").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!PAGINAREGBATTESIMO))
.ActiveDocument.Bookmarks("num").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!NUMEROREGBATTESIMO))
.ActiveDocument.Bookmarks("cog").Select
objWord.Selection.Font.AllCaps = True
.Selection.Text = (CStr(Forms!m_bb_anaview!COGNOME))
.ActiveDocument.Bookmarks("nom").Select
objWord.Selection.Font.AllCaps = True
.Selection.Text = (CStr(Forms!m_bb_anaview!NOME))
.ActiveDocument.Bookmarks("lnasc").Select
objWord.Selection.Font.AllCaps = True
.Selection.Text = (CStr(Forms!m_bb_anaview!LUOGODINASCITA))
.ActiveDocument.Bookmarks("dnasc").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!DATADINASCITA))
.ActiveDocument.Bookmarks("gbatt").Select
.Selection.Text = (Day(Forms!m_bb_anaview!DATADIBATTESIMO))
.ActiveDocument.Bookmarks("mbatt").Select
.Selection.Text = (MonthName(Month(Forms!m_bb_anaview!DATADIBATTESIMO)))
.ActiveDocument.Bookmarks("abatt").Select
.Selection.Text = (Year(Forms!m_bb_anaview!DATADIBATTESIMO))
.ActiveDocument.Bookmarks("dcresima").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!DATADICRESIMA))
.ActiveDocument.Bookmarks("parcresima").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!LUOGODICRESIMA))
.ActiveDocument.Bookmarks("diocesicresima").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!DIOCESIDICRESIMA))
.ActiveDocument.Bookmarks("cogconiuge").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!COGNOME))
.ActiveDocument.Bookmarks("nomconiuge").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!NOME))
.ActiveDocument.Bookmarks("dmatr").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!DATADIMATRIMONIO))
.ActiveDocument.Bookmarks("parmatr").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!PARROCCHIADIMATRIMONIO))
.ActiveDocument.Bookmarks("diocesimatr").Select
.Selection.Text = (CStr(Forms!m_bb_anaview!DIOCESIDIMATRIMONIO))
End With
M02_batt_Err:
'If a field on the form is empty, remove the bookmark text, and 'continue'
'objWord.Application.WordBasic.MsgBox "Verificare il certificato, mancono dei dati.", "ATTENZIONE!"'
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
End Sub