Kod:
Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WordApp = CreateObject("Word.Application")
End If
WordApp.Visible = True
WordApp.WindowState = wdWindowStateMaximize
WordApp.Documents.Add Template:=strTemplateLocation, NewTemplate:=False
With WordApp.Selection
Dim objRecordset As ADODB.Recordset
Set objRecordset = New ADODB.Recordset
Dim i As Integer
Dim value As Variant
'initated recordset obejct
objRecordset.ActiveConnection = CurrentProject.Connection
objRecordset.Open ("Select ea_no, be_no, uygulama, alan_adres, alan_adi, veri_adres" & _
" From tbl_evrakhazirlaalanlistesi" & _
" Where be_no =" & e_no)
'find the target record
While objRecordset.EOF = False
'check for match
dataadres = objRecordset.Fields(3).value
veri = objRecordset.Fields(5).value
'veriform = Me(veri).value ' Veritabanından çekilen veriyi formda buluyorum.
If IsNull(Me(veri).value) Then
veriform = " "
Else
veriform = Me(veri).value ' Veritabanından çekilen veriyi formda buluyorum.
End If
If IsNull(veriform) Then
.GoTo what:=wdGoToBookmark, Name:=dataadres
.TypeText " "
MsgBox dataadres, vbCritical
Else
.GoTo what:=wdGoToBookmark, Name:=dataadres
.TypeText veriform
End If
objRecordset.MoveNext
Wend
Dim Path4 As String
Path4 = CurrentProject.Path & "/Ödeme Takibi Uygulaması/Arşiv/" & [İş] & "/" & [Kimlik] & " - " & [Firma] & "/"
Dim FileN As String
Dim both As String
FileN = h_evrak & "-" & [Fatura No] & ".doc"
both = Path4 & FileN
WordApp.ActiveDocument.SaveAs FileName:=both, FileFormat:=wdFormatText
Set WordApp = Nothing
DoEvents
End With
Exit Sub
ErrHandler:
Set WordApp = Nothing
MsgBox "error"
End If
End Sub