Componer recordset con variables.
Publicado por Josu (3 intervenciones) el 06/03/2013 08:48:29
Buenas, tengo el código copiado abajo con el que en access 2000 consigo abrir una plantilla de word, detectar mediante un recorset los marcadores del documento e insertar campos.
El fallo es que, en lugar de insertar el valor del campo que deseo, me inserta el nombre del recorset. Algo estoy haciendo mal al asignar el valor de la variable. Agradecería toda ayuda posible para este humilde peón del software. Muchas gracias.
El fallo es que, en lugar de insertar el valor del campo que deseo, me inserta el nombre del recorset. Algo estoy haciendo mal al asignar el valor de la variable. Agradecería toda ayuda posible para este humilde peón del software. Muchas gracias.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Private Sub Comando170_Click()
On Error GoTo Err_Comando170_Click
Dim strPlantilla As String
Dim strSQL1 As String
Dim strSQL2 As String
Dim strMensaje As String
Dim appWord As Word.Application
Dim wordDoc As Word.Document
Dim strCampoA As Object
Dim strCampoB As Object
Dim strMarcador As String
Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
'IDENTIFICAMOS NOMBRE DE LA PLANTILLA EN FUNCION DEL VALOR DEL COMBO
strPlantilla = DLookup("[PLANTILLA_TAREA]", "PRL_ER_tbl_procedimientos_TAREAS", "[TAREA_PROCEDIMIENTO_ID]=" & Me![TAREA])
strMensaje = "Has seleccionado la plantilla: " & vbCrLf & vbCrLf & strPlantilla
MsgBox strMensaje, vbInformation + vbOKOnly, "Título cuadro mensaje"
Set appWord = New Word.Application
With appWord
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set wordDoc = appWord.Documents.Add(CurrentProject.Path & "\Prevencion\PLANTILLAS\" & strPlantilla)
strSQL1 = "SELECT * FROM PRL_ER_tbl_procedimientos_TAREAS "
strSQL1 = strSQL1 & "INNER JOIN PRL_ER_tbl_procedimientos_tareas_MARCADORES "
strSQL1 = strSQL1 & "ON PRL_ER_tbl_procedimientos_TAREAS.[TAREA_PROCEDIMIENTO_ID] = PRL_ER_tbl_procedimientos_tareas_MARCADORES.[TAREA_PROCEDIMIENTO_ID] "
strSQL1 = strSQL1 & "WHERE PRL_ER_tbl_procedimientos_TAREAS.[TAREA_PROCEDIMIENTO_ID]= " & Me![TAREA]
Set rst1 = CurrentDb.OpenRecordset(strSQL1)
strSQL2 = "SELECT EMPLEADOS.*, PRL_IS_tbl_INCIDENCIAS_SALUD.* FROM PRL_IS_tbl_INCIDENCIAS_SALUD "
strSQL2 = strSQL2 & "INNER JOIN EMPLEADOS "
strSQL2 = strSQL2 & "ON PRL_IS_tbl_INCIDENCIAS_SALUD.[DNI] = EMPLEADOS.[DNI] "
strSQL2 = strSQL2 & "WHERE PRL_IS_tbl_INCIDENCIAS_SALUD.[IDINCIDENCIA]= " & Me![IDINCIDENCIA]
Set rst2 = CurrentDb.OpenRecordset(strSQL2)
If Not (rst1.EOF And rst1.BOF) Then
Do
'***********************************************************************************************************
'NO FUNCIONA EL RECORDSET!! No logro referenciar bien el valor del rst2 mediante una variable
***********************************************************************************************************
Set strCampoA = rst1!CAMPO_TABLA
Set strCampoB = rst2.Fields(strCampoA)
strMarcador = rst1!MARCADOR_DOC
wordDoc.Bookmarks(strMarcador).Range.Text = strCampoB
rst1.MoveNext
Loop Until rst1.EOF
End If
strPlantilla = ""
Set rst1 = Nothing
Set rst2 = Nothing
Set appWord = Nothing
Set wordDoc = Nothing
Exit_Comando170_Click:
Exit Sub
Err_Comando170_Click:
MsgBox Err.Description
Resume Exit_Comando170_Click
End Sub
Valora esta pregunta


0