Hi everyone, I have this code on a cmdButton on a form:
The code works as designed the first time the cmd button is clicked. There after the word document opens as blank. I thought the form recordset was "active" for the entire time the form was visible. Requerying the form didn't work creating an error no current record. How do I get the code tor run properly more than once? thanks
Public Sub WordEx()
Set WordApp = New Word.Application
WordApp.Documents.Add
Set doc = WordApp.ActiveDocument
Set sel = WordApp.Selection
WordApp.Visible = True
End Sub
Private Sub cmdCopy_Click()
'On Error GoTo Err_cmdCopy_Click
Dim db As DAO.Database
Set db = CurrentDb()
Dim rs As DAO.Recordset
Dim fld As DAO.Field, strSQL As String
Set rs = Screen.ActiveForm.RecordsetClone
'Me.Requery
Select Case Me.Frame2
Case Is = 1
Set fld = rs.Fields(4)
Case Is = 2
Set fld = rs.Fields(5)
End Select
WordEx
Do Until rs.EOF
sel.TypeText Text:=fld.Value & vbCrLf & vbCrLf
rs.MoveNext
Loop
Exit_cmdCopy_Click:
Exit Sub
Err_cmdCopy_Click:
MsgBox Err.Description
Resume Exit_cmdCopy_Click
End Sub