Private Sub Komut4_Click()
CurrentDb.Execute "insert into Tablo2 (ad,soyad,tc)" _
& " select '" & Me.ad & "' , '" & Me.soyad & "','" & Me.tc & "'"
Dim oApp As Object
Set oApp = CreateObject("Word.Application")
Dim oMainDoc As Word.Document
Dim oSel As Word.Selection
Dim sDBPath As String
Set oMainDoc = oApp.Documents.Open("C:\Users\savaş\Desktop\1.doc")
oApp.Visible = True
With oMainDoc.MailMerge
.MainDocumentType = wdCatalog
sDBPath = "C:\Users\savaş\Desktop\insert.accdb"
.OpenDataSource Name:=sDBPath, _
SQLStatement:="SELECT * FROM [Tablo2]"
End With
With oMainDoc
.MailMerge.Destination = wdSendToNewDocument
.MailMerge.Execute
End With
oApp.Activate
oApp.Documents.Parent.Visible = True
oApp.Application.WindowState = 1
oApp.ActiveWindow.WindowState = 1
oMainDoc.Close
Set oApp = Nothing
End Sub
buraya kadar normal evrak hazır oluyor. ancak başka kullanıcı da aynı işlemi uygulayınca tabloda ikinci bir satır oluşuyor. ikinci insert işlemi nedeniyle. üçüncü kullanıcıda aynı işlemi yapınca 3. satır oluşuyor. dolayısıyla 3 tane ayrı evrak oluşturuluyor.
DoCmd.SetWarnings False
DoCmd.RunSQL "delete * from Tablo2"
DoCmd.SetWarnings True
Bu kodu ilk kodun sonuna yazınca da mektup birleştirme olmadan veriler siliniyor ek te ki resim gibi oluyor.