Tenho um formulário para me exportar para word, o problema é com o critério que me duplica os campos. O código que duplica é:
If Me.CaixaCombinação370.Value <> "Heroina" Or Me.CaixaCombinação370.Value <> "Cocaina" Or Me.CaixaCombinação370.Value <> "Haxixe" Or Me.CaixaCombinação370.Value <> "Liamba" Or Me.CaixaCombinação370.Value <> "Ecstasy" Then
.ActiveDocument.Bookmarks("Texto13").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação370)
.ActiveDocument.Bookmarks("TCD13").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("TCD14").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("TCD15").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
Else
Resume Next
End If
Não consigo descobrir porque duplica o código completo é:
Private Sub Comando499_Click()
Dim wdApl As Object
Set wdApl = CreateObject("Word.Application")
wdApl.Documents.Open FileName:=CurrentProject.Path & "\Formulário TCD A.docx"
With wdApl
.ActiveDocument.Bookmarks("Texto1").Select: .Selection.text = Nz(Forms!Droga.Rótulo615) 'Processo
.ActiveDocument.Bookmarks("Texto3").Select: .Selection.text = Nz(Forms!Droga.Texto400) 'Data
.ActiveDocument.Bookmarks("Texto7").Select: .Selection.text = Nz(Forms!Droga.TCD_Freguesia)
.ActiveDocument.Bookmarks("Texto8").Select: .Selection.text = Nz(Forms!Droga.TCD_Concelho)
.ActiveDocument.Bookmarks("Texto9").Select: .Selection.text = Nz(Forms!Droga.TCD_Distrito)
.ActiveDocument.Bookmarks("Texto14").Select: .Selection.text = Nz(Forms!Droga.TCD_Dissimulado)
.ActiveDocument.Bookmarks("Texto15").Select: .Selection.text = Nz(Forms!Droga.TCD_Local)
.ActiveDocument.Bookmarks("Texto16").Select: .Selection.text = Nz(Forms!Droga.TCD_Internacional_De)
.ActiveDocument.Bookmarks("Texto17").Select: .Selection.text = Nz(Forms!Droga.TCD_Internacional_Para)
.ActiveDocument.Bookmarks("Texto18").Select: .Selection.text = Nz(Forms!Droga.TCD_LOcalproduçao)
.ActiveDocument.Bookmarks("TCD_111").Select: .Selection.text = Nz(Forms!Droga.TCD_Interno_De)
.ActiveDocument.Bookmarks("TCD222").Select: .Selection.text = Nz(Forms!Droga.TCD_Interno_Para)
.ActiveDocument.Bookmarks("Texto20").Select: .Selection.text = Nz(Forms!Droga.TCD_Transporte_Matricula)
.ActiveDocument.Bookmarks("Texto21").Select: .Selection.text = Nz(Forms!Droga.TCD_Barco)
.ActiveDocument.Bookmarks("Texto22").Select: .Selection.text = Nz(Forms!Droga.TCD_Outro)
.ActiveDocument.Bookmarks("Texto23").Select: .Selection.text = Nz(Forms!Droga.TCD_Bensapreendidos)
.ActiveDocument.Bookmarks("Texto24").Select: .Selection.text = Nz(Forms!Droga.TCD_Detidos)
.ActiveDocument.Bookmarks("Texto25").Select: .Selection.text = Nz(Forms!Droga.TCD_NãoDetidos)
.ActiveDocument.Bookmarks("Texto26").Select: .Selection.text = Nz(Forms!Droga.TCD_Total)
If Me.CaixaCombinação370 = "Heroina" Then
.ActiveDocument.Bookmarks("TCD123").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("Texto11").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("Texto12").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
End If
If Me.CaixaCombinação370 = "Cocaina" Then
.ActiveDocument.Bookmarks("Texto10").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("TCD11").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("TCD12").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
End If
If Me.CaixaCombinação370 = "Haxixe" Then
.ActiveDocument.Bookmarks("TCD2").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("TCD3").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("TCD4").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
End If
If Me.CaixaCombinação370 = "Liamba" Then
.ActiveDocument.Bookmarks("TCD5").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("TCD6").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("TCD7").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
End If
If Me.CaixaCombinação370 = "Ecstasy" Then
.ActiveDocument.Bookmarks("TCD8").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("TCD9").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("TCD10").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
End If
If Me.CaixaCombinação370.Value <> "Heroina" Or Me.CaixaCombinação370.Value <> "Cocaina" Or Me.CaixaCombinação370.Value <> "Haxixe" Or Me.CaixaCombinação370.Value <> "Liamba" Or Me.CaixaCombinação370.Value <> "Ecstasy" Then
.ActiveDocument.Bookmarks("Texto13").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação370)
.ActiveDocument.Bookmarks("TCD13").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("TCD14").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("TCD15").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
Else
Resume Next
End If
.ActiveDocument.SaveAs CurrentProject.Path & "\Processos Crime\" & Nz(Replace(Me!Rótulo615, "/", "_")) & " - Formulário TCD A" & ".docx"
.ActiveDocument.Close
.Quit
End With
Set wdApl = Nothing
MsgBox "''Formulário TCD A'' gerado em Word com sucesso na pasta ''Processos Crime''.", vbInformation, "Aviso"
End Sub
Fica assim:
If Me.CaixaCombinação370.Value <> "Heroina" Or Me.CaixaCombinação370.Value <> "Cocaina" Or Me.CaixaCombinação370.Value <> "Haxixe" Or Me.CaixaCombinação370.Value <> "Liamba" Or Me.CaixaCombinação370.Value <> "Ecstasy" Then
.ActiveDocument.Bookmarks("Texto13").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação370)
.ActiveDocument.Bookmarks("TCD13").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("TCD14").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("TCD15").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
Else
Resume Next
End If
Não consigo descobrir porque duplica o código completo é:
Private Sub Comando499_Click()
Dim wdApl As Object
Set wdApl = CreateObject("Word.Application")
wdApl.Documents.Open FileName:=CurrentProject.Path & "\Formulário TCD A.docx"
With wdApl
.ActiveDocument.Bookmarks("Texto1").Select: .Selection.text = Nz(Forms!Droga.Rótulo615) 'Processo
.ActiveDocument.Bookmarks("Texto3").Select: .Selection.text = Nz(Forms!Droga.Texto400) 'Data
.ActiveDocument.Bookmarks("Texto7").Select: .Selection.text = Nz(Forms!Droga.TCD_Freguesia)
.ActiveDocument.Bookmarks("Texto8").Select: .Selection.text = Nz(Forms!Droga.TCD_Concelho)
.ActiveDocument.Bookmarks("Texto9").Select: .Selection.text = Nz(Forms!Droga.TCD_Distrito)
.ActiveDocument.Bookmarks("Texto14").Select: .Selection.text = Nz(Forms!Droga.TCD_Dissimulado)
.ActiveDocument.Bookmarks("Texto15").Select: .Selection.text = Nz(Forms!Droga.TCD_Local)
.ActiveDocument.Bookmarks("Texto16").Select: .Selection.text = Nz(Forms!Droga.TCD_Internacional_De)
.ActiveDocument.Bookmarks("Texto17").Select: .Selection.text = Nz(Forms!Droga.TCD_Internacional_Para)
.ActiveDocument.Bookmarks("Texto18").Select: .Selection.text = Nz(Forms!Droga.TCD_LOcalproduçao)
.ActiveDocument.Bookmarks("TCD_111").Select: .Selection.text = Nz(Forms!Droga.TCD_Interno_De)
.ActiveDocument.Bookmarks("TCD222").Select: .Selection.text = Nz(Forms!Droga.TCD_Interno_Para)
.ActiveDocument.Bookmarks("Texto20").Select: .Selection.text = Nz(Forms!Droga.TCD_Transporte_Matricula)
.ActiveDocument.Bookmarks("Texto21").Select: .Selection.text = Nz(Forms!Droga.TCD_Barco)
.ActiveDocument.Bookmarks("Texto22").Select: .Selection.text = Nz(Forms!Droga.TCD_Outro)
.ActiveDocument.Bookmarks("Texto23").Select: .Selection.text = Nz(Forms!Droga.TCD_Bensapreendidos)
.ActiveDocument.Bookmarks("Texto24").Select: .Selection.text = Nz(Forms!Droga.TCD_Detidos)
.ActiveDocument.Bookmarks("Texto25").Select: .Selection.text = Nz(Forms!Droga.TCD_NãoDetidos)
.ActiveDocument.Bookmarks("Texto26").Select: .Selection.text = Nz(Forms!Droga.TCD_Total)
If Me.CaixaCombinação370 = "Heroina" Then
.ActiveDocument.Bookmarks("TCD123").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("Texto11").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("Texto12").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
End If
If Me.CaixaCombinação370 = "Cocaina" Then
.ActiveDocument.Bookmarks("Texto10").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("TCD11").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("TCD12").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
End If
If Me.CaixaCombinação370 = "Haxixe" Then
.ActiveDocument.Bookmarks("TCD2").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("TCD3").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("TCD4").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
End If
If Me.CaixaCombinação370 = "Liamba" Then
.ActiveDocument.Bookmarks("TCD5").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("TCD6").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("TCD7").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
End If
If Me.CaixaCombinação370 = "Ecstasy" Then
.ActiveDocument.Bookmarks("TCD8").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("TCD9").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("TCD10").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
End If
If Me.CaixaCombinação370.Value <> "Heroina" Or Me.CaixaCombinação370.Value <> "Cocaina" Or Me.CaixaCombinação370.Value <> "Haxixe" Or Me.CaixaCombinação370.Value <> "Liamba" Or Me.CaixaCombinação370.Value <> "Ecstasy" Then
.ActiveDocument.Bookmarks("Texto13").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação370)
.ActiveDocument.Bookmarks("TCD13").Select: .Selection.text = Nz(Forms!Droga.Texto21) & "/" & Nz(Forms!Droga.CaixaCombinação448)
.ActiveDocument.Bookmarks("TCD14").Select: .Selection.text = Nz(Forms!Droga.Texto37) & "/" & Nz(Forms!Droga.CaixaCombinação418) & "/" & Nz(Forms!Droga.Texto33)
.ActiveDocument.Bookmarks("TCD15").Select: .Selection.text = Nz(Forms!Droga.CaixaCombinação379)
Else
Resume Next
End If
.ActiveDocument.SaveAs CurrentProject.Path & "\Processos Crime\" & Nz(Replace(Me!Rótulo615, "/", "_")) & " - Formulário TCD A" & ".docx"
.ActiveDocument.Close
.Quit
End With
Set wdApl = Nothing
MsgBox "''Formulário TCD A'' gerado em Word com sucesso na pasta ''Processos Crime''.", vbInformation, "Aviso"
End Sub
Fica assim: