Question : Access 2003 to Word 2003:  quest 2:    where can i put these 2 lines of code, bec. now it's giving me an error

Hi EE,

a) I copied these 2 lines of code from this related EE post, and am getting this error:
                   error no 13, type mismatch

          For Each prp In prps
              Debug.Print prp.Name & " : " & prp.Value
          Next

b)  The fields are dimmed as follows:
        Dim prps                   As Object   (i would get error msg when vba executed if dimmed as DocumentProperties)
        Dim prp                    As DocumentProperty


c) background:
    --------------
            1) opening and existing WORD doc that has:
                        2) properties (to populate with Student Info)
                        3) a table, where the 1st element of the table hold the Student's picture

tx for your ideas, sandra
Code Snippet:
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:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
Option Compare Database

Option Explicit

Public Sub cmdWordEvaluations_Click_CHECKBOXES(strTableName_Students As String, _
                                              strBackLabelStatus As Boolean)
                               
On Error GoTo ErrorHandler

'  objects
Dim appWord                As Word.Application
Dim docs                   As Word.Documents

Dim ilImage                As Object
Dim dTable                 As Word.Table
Dim prps                   As Object
Dim prp                    As DocumentProperty

Dim db                     As DAO.Database
Dim rst                    As DAO.Recordset

' strings

Dim strBackSql             As String
Dim strTest                As String
Dim strImageFile           As String
Dim strSubPDFFolder        As String

Dim strTemplateDir         As String
Dim strWordFile            As String
Dim strPDFFile             As String
Dim strFullPath            As String

Dim strMsg                 As String
Dim strrst                 As String

' longs
Dim lngCount               As Long
Dim lngResponse            As Long
Dim lngWordCount           As Long
Dim lngBegCount            As Long

Dim lngBackRowCount        As Long
Dim blnBackGoodIO          As Boolean


Set db = CurrentDb()

'=================================================


Call q823_Select_Table_Students_COUNT_Checkboxes _
                                    (strTableName_Students, _
                                     blnBackGoodIO, _
                                     lngBackRowCount)
  
Debug.Print lngBackRowCount    '      Recordset.Fields("ROWCOUNT") is the number of rows...
     
'=====================================================================

   
   
If lngBackRowCount = 0 Then
   MsgBox "No records to export"
   GoTo finishup
Else
    strMsg = lngBackRowCount & _
                  " Evaluation Report(s) sending to Word"

    strBackLabelStatus = True

    lngResponse = MsgBox(strMsg, vbInformation + vbOKCancel + vbDefaultButton1, _
                         "Please be advised...")
    If lngResponse = vbCancel Then
        strBackLabelStatus = False
        GoTo finishup
    End If

 End If

' ============================

Call q925_set_sql_rst_for_labels_CHECKBOXES _
                           (strTableName_Students, _
                            strBackSql)
   
Set rst = db.OpenRecordset(strBackSql)
strrst = "y"
   
      
' ============================
     
   'Open Word
   Set appWord = GetObject(, "Word.Application")
      
   
   'Pick up Word user templates folder from Registry
    strTest = appWord.Options.DefaultFilePath(wdUserTemplatesPath)
   
   'set word doc name
   strWordFile = "wClerkshipEvaluationForm_FIELDS.doc"
   strFullPath = CurrentProject.Path & "\" & strWordFile
   
   strSubPDFFolder = "Evaluation_ for_Clerkship"
      
   Debug.Print "Opening document based on template: " & strFullPath
   
 
   ' open copy of template
   Set docs = appWord.Documents
   docs.Open strFullPath
   
   'Set doc = appWord.ActiveDocument
   
   appWord.Visible = True
   
   'Loop through table, exporting each record to Word
   ' http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_21152049.html?sfQueryTermInfo=1+selection.inlineshapes.addpictur
   ' http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_23785214.html?sfQueryTermInfo=1+cell+popul+tabl+word
   
   Do Until rst.EOF
                      
          Debug.Print rst!S_LName & " " & rst!S_FName; " " & rst!S_Id
                              
                               
'          With appWord.ActiveDocument
'            Set prps = .CustomDocumentProperties
'            Set dTable = .Tables(1)
'          End With
          
       '   similar to with/end with construct above
          Set dTable = ActiveDocument.Tables(1)
          Set prps = ActiveDocument.CustomDocumentProperties
          
                    
'          For Each prp In prps
'              Debug.Print prp.Name & " : " & prp.Value
'          Next
  
                     
        ' ======================
        ' populate Properties and update document
        ' ======================
           With prps
           
               .Item("w_FullName").Value = rst!S_LName & ", " & rst!S_FName
               .Item("w_Attrib").Value = "M3"
               .Item("w_Clerkship").Value = "test clerkship"
               .Item("w_Date_From").Value = vbNullString
               .Item("w_Date_To").Value = vbNullString
           End With
           
           
' i copied this from internet, not sure if i need it
'  This will make sure all fields are updated when you open the file.
'  It is also possible to update specific fields instead all.
           
           With appWord.Selection
               .WholeStory
               .fields.Update
               .MoveDown Unit:=wdLine, Count:=1
           End With
          
    '========================
    ' position to first element of table to insert picture
    '========================
    
          dTable.Select
          Selection.MoveRight Unit:=wdCell, Count:=1
            
          'As a test, Insert a literal into the table element that really holds the picture
          Selection.Text = "Insert Picture Here"
             
            
                               
          ' add in line image
            strImageFile = "O:\COM Photos\MED Pics Banner\" & _
                               rst!S_Id & ".jpg"

          
            Set ilImage = Selection.InlineShapes.AddPicture(strImageFile, _
                                                          LinkToFile:=False, _
                                                          SaveWithDocument:=True)
          
nextrec:
         rst.MoveNext
   Loop
   
   
   appWord.Selection.HomeKey Unit:=wdStory
   

   appWord.Activate
   
   
   
finishup:


If strrst = "y" Then
   rst.Close
End If

db.Close


Set appWord = Nothing
Set docs = Nothing

Set ilImage = Nothing
Set dTable = Nothing
Set prps = Nothing
Set prp = Nothing

Set db = Nothing
Set rst = Nothing

  
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

Answer : Access 2003 to Word 2003:  quest 2:    where can i put these 2 lines of code, bec. now it's giving me an error

Hi Sandra,
You need to understand the difference between early vs late binding of object variables, and the use of the set statement.  See these links:
                               http://word.mvps.org/fAQs/InterDev/EarlyvsLateBinding.htm
                               http://msdn.microsoft.com/en-us/library/aa140523(office.10).aspx
Random Solutions  
 
programming4us programming4us