sábado, abril 12, 2014

miércoles, junio 05, 2013

martes, mayo 14, 2013

Word Editable

Private Sub btnWord_Click()
    Dim applicationword As Word.Application
    Set applicationword = New Word.Application
    Dim TargetName As String
    Dim TargetPDF As String
   
    TargetName = "C:\Users\sergio calvo\Documents\Word\Estimado.
docx"
    TargetPDF = "C:\Users\sergio calvo\Documents\Word\Estimado.pdf"
    applicationword.Documents.Open "C:\Users\sergio calvo\Documents\Word\Estimado.docx"
   
    With applicationword
        .Visible = True
       
        .Activate
    End With

    Dim cuadrodetexto As ContentControl
    Dim coleccioncuadrodetexto As ContentControls
   
    Set coleccioncuadrodetexto = applicationword.ActiveDocument.SelectContentControlsByTag("editnomAp")
   
   
    For Each cuadrodetexto In coleccioncuadrodetexto
        cuadrodetexto.Range.Text = editNombre & editAp
    Next
   
     Set coleccioncuadrodetexto = applicationword.ActiveDocument.SelectContentControlsByTag("editDNI")
   
   
    For Each cuadrodetexto In coleccioncuadrodetexto
        cuadrodetexto.Range.Text = editDni
    Next
   
    'guardar en word
    applicationword.ActiveDocument.SaveAs2 TargetName
    'guardar en pdf
    applicationword.ActiveDocument.ExportAsFixedFormat TargetPDF, wdExportFormatPDF, True
   
    applicationword.ActiveDocument.Close True
    'applicationword.ActiveDocument.Close
   
    Set applicationword = Nothing
End Sub

Exportar bbdd word pdf

Private Sub Comando0_Click()
   
    Dim applicationword As Word.Application
    Set applicationword = New Word.Application
    Dim TargetName As String
    Dim TargetPDF As String
   
    TargetName = "C:\Users\sergio calvo\Documents\Word\Coches.
docx"
    TargetPDF = "C:\Users\sergio calvo\Documents\Word\Coches.pdf"
    'applicationword.Documents.Open "C:\Users\sergio calvo\Documents\Word\Estimado.docx"
   
    With applicationword
   
        .Visible = True
        .Activate
       
    End With
   
    applicationword.Documents.Add
   
    Dim rs As Recordset
    Dim sql As String
   
    sql = "SELECT * from [Vehículos]"
    Set rs = CurrentDb.OpenRecordset(sql)

    If Not (rs.BOF And rs.EOF) Then
        rs.MoveFirst
    End If
   
    While Not rs.EOF
       
        applicationword.Selection.TypeText rs.Fields("Gama").Value
        'applicationword.Selection.TypeParagraph
        applicationword.Selection.TypeText " "
        applicationword.Selection.TypeText rs.Fields("Modelo").Value
        applicationword.Selection.TypeParagraph
       
        rs.MoveNext
       
   
    Wend
   
    rs.Close
    'Dim cuadrodetexto As ContentControl
    'Dim coleccioncuadrodetexto As ContentControls
   
    'Set coleccioncuadrodetexto = applicationword.ActiveDocument.SelectContentControlsByTag("editnomAp")
   
   
    'For Each cuadrodetexto In coleccioncuadrodetexto
    '    cuadrodetexto.Range.Text = editNombre & editAp
    'Next
   
     'Set coleccioncuadrodetexto = applicationword.ActiveDocument.SelectContentControlsByTag("editDNI")
   
   
    'For Each cuadrodetexto In coleccioncuadrodetexto
    '    cuadrodetexto.Range.Text = editDni
    'Next
   
    'guardar en word
    applicationword.ActiveDocument.SaveAs2 TargetName
    'guardar en pdf
    applicationword.ActiveDocument.ExportAsFixedFormat TargetPDF, wdExportFormatPDF, True
   
    applicationword.ActiveDocument.Close True
    'applicationword.ActiveDocument.Close
   
    Set applicationword = Nothing
   

End Sub

vba actualizar y añadir

Private Sub btnCerrar_Click()
    Unload Me
End Sub

Private Sub btnRellenar_Click()
    Dim rs As New ADODB.Recordset
    Dim cn As New ADODB.Connection
    Dim esta As Boolean
    Dim sql As String
    esta = False
    sql = "select * from [Cuentas de clientes]"

    cn.Open "Provider=Microsoft.ACE.OLEDB.
12.0;Data Source=C:\Users\sergio calvo\Documents\Access\concesionario.accdb"
   
    rs.CursorLocation = adUseClient
    rs.Open sql, cn, adOpenKeyset, adLockOptimistic
   
    If Not (rs.BOF And rs.EOF) Then
        rs.MoveFirst
        While Not rs.EOF
            If rs.Fields("DNI").Value = editDNI.Text Then
                esta = True
                rs.MoveLast
            End If
            rs.MoveNext
        Wend
    End If
   
    If Not esta Then
        rs.AddNew
        rs.Fields("DNI").Value = editDNI.Text
        rs.Fields("Nombre").Value = editNombre.Text
        rs.Fields("Apellido").Value = editAp.Text
        rs.Update
       
        editDNI.Text = ""
        editNombre.Text = ""
        editAp.Text = ""
    Else
        MsgBox "El DNI ya se encuentra en la base de datos"
    End If

    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
   
   
End Sub

Private Sub editDNI_AfterUpdate()
    Dim rs As New Recordset
    Dim cn As New Connection
  
    cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sergio calvo\Documents\Access\concesionario.accdb"
   
    rs.CursorLocation = adUseClient
    rs.Open "select * from [Cuentas de clientes]", cn, adOpenDynamic
   
    If Not (rs.BOF And rs.EOF) Then
        rs.MoveFirst
        While Not rs.EOF
            If rs.Fields("DNI").Value = editDNI.Text Then
                editNombre.Text = rs.Fields("Nombre")
                editAp.Text = rs.Fields("Apellido")
            End If
            rs.MoveNext
        Wend
    End If

    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
End Sub