Si ho un loop in word che riempie la tabella.
La chiamata in access è:
objDocInserto.Application.Run "Inserimento", Replace(rstDatiSubmodelli!query, "[inserisci_qui_il_filtro]", chiave_slave), _
rstDatiSubmodelli!n_campi, rstDatiSubmodelli!sequenza, ModoDebugLocale, Form_mPrincipale.Connessione
Il codice in word è:
Public Sub Inserimento(query As String, nCampi As Integer, sequenza As Integer, ModoDebug As Integer, ConnString As String) 'As Integer ' nome As String, query As String)
On Error GoTo errore
Dim wrkMain As Workspace
Dim BaseDati As Database
Dim Proprieta As Property
Dim k As Integer
Dim segnalibro As String
Dim rst As DAO.Recordset
10 Set wrkMain = CreateWorkspace("", "admin", "", dbUseJet)
20 Set BaseDati = wrkMain.OpenDatabase("StudioM", dbDriverNoPrompt, False, ConnString)
30 Set rst = BaseDati.OpenRecordset(query)
35 rst.MoveFirst
40 segnalibro = "Contenuto" & sequenza
50 ThisDocument.Bookmarks(segnalibro).Select
Select Case sequenza
Case 3
60 rst.MoveFirst
70 If Not rst.EOF Then
80 While Not rst.EOF
90 For k = 0 To (nCampi - 1)
100 Selection.TypeText (CStr(IIf(IsNull(rst.Fields(k).Value), "", rst.Fields(k).Value)))
110 If Not (k = nCampi - 1) Then Selection.MoveDown '.MoveRight (12)
Next
120 rst.MoveNext
130 If rst.EOF Then
Else
140 Selection.Rows.Add
150 Selection.MoveRight (12)
Selection.MoveEnd wdLine, -1
Selection.MoveDown
End If
Wend
End If
Case 4
155 rst.MoveFirst
160 If Not rst.EOF Then
165 While Not rst.EOF
170 For k = 0 To (nCampi - 1)
190 Selection.TypeText (CStr(IIf(IsNull(rst.Fields(k).Value), "", rst.Fields(k).Value)))
200 If Not (k = nCampi - 1) Then Selection.MoveDown
Next
210 rst.MoveNext
220 If rst.EOF Then
Else
230 Selection.Rows.Add
240 Selection.MoveRight (12)
Selection.MoveEnd wdLine, -1
Selection.MoveDown
End If
Wend
End If
Case Else
250 rst.MoveFirst
260 If Not rst.EOF Then
270 While Not rst.EOF
280 For k = 0 To (nCampi - 1)
290 If InStr(1, rst.Fields(k).Value, "#") Then
'Selection.InlineShapes.AddPicture (rstInfoCartella!indirizzo_archivio & "\Segnalazioni\" & Replace(rstContenuto.Fields(k).Value, "#", "") & ".jpg")
Else
300 Selection.TypeText (CStr(IIf(IsNull(rst.Fields(k).Value), "", rst.Fields(k).Value)))
End If
310 If Not (k = nCampi - 1) Then Selection.MoveRight (12)
Next
320 rst.MoveNext
330 If rst.EOF Then
Else
340 Selection.Rows.Add
350 Selection.HomeKey (5) 'Unit:=wdLine
End If
Wend
End If
End Select
360 ThisDocument.Bookmarks(segnalibro).Delete
'Inserimento = 1
rst.Close
Set rst = Nothing
Exit Sub
errore:
Select Case Err.Number
Case 0
Resume Next
Case Else
If ModoDebug Then
MsgBox "WORD ERROR HANDLER" & vbCrLf & _
"Documento Valutazione f() Inserimento " & vbCrLf & _
"Value: " & Err.Number & vbCrLf & _
"Error Line: " & Erl & vbCrLf & _
"Error: " & Err.Description, vbCritical
Debug.Assert False
Resume
Else
Resume Next
End If
End Select
End Sub
Se in access metto un breakpoint, mi si ferma, vado in vba di word, metto il bp sull'onerror funziona.
Se tolgo il bp in access e lo metto alla riga successiva esegue senza dar cenno di errori ma non facendo nessun inserimento, nemmeno va al segnalibro alla riga 50.