Cerrar un formulario por medio de botón después de ejecutar instrucciones.

Buen día, es un gusto saludarte y espero me puedas ayudar con este tema que en realidad le he buscado y no me funciona, haz de recordar ese botón muy bien jijijijiji.

Lo que quiero es que después de cumplir las instrucciones que ya funcionan bien me cierre el formulario llamado cotización: ESTE ES EL CÓDIGO QUE TENGO Y AUN ASÍ NO JALA

Private Sub pdfcorreo_Click()
Me.subtotal = Me.txtsubtotal
Me.subdesc1 = Me.txtdescuento1
Me.subtotaldesc2 = Me.txtsubtotaldesc2
Me.subdesc2 = Me.txtdescuento2
Me.subtotal2 = Me.txtsubtotal2
Me.iva = Me.txtiva
Me.total = Me.txttotal
Me.cantidadconletra = Me.PrecioenLetra
Me.ESTATUS = "EMITIDO"
Me.Refresh
'Author : Ken Puls ( www.excelguru.ca)
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from http://sourceforge.net/projects/pdfcreator/ )
' Designed for early bind, set reference to PDFCreator
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim sPrinterName As String
Dim sReportName As String
Dim lPrinters As Long
Dim lPrinterCurrent As Long
Dim lPrinterPDF As Long
Dim prtDefault As Printer
'/// Change the report and output file name here! ///
Dim nomArchivo As String
sReportName = "cotización"
sPDFName = "PRESUPUESTO No." & Me.nodecotizacion & "-" & Format(Date, "dd.mm.yy") & ".pdf"
sPDFPath = "c:\informes\"
'Resolve index number of printers to allow changing and preserving
sPrinterName = Application.Printer.DeviceName
On Error Resume Next
For lPrinters = 0 To Application.Printers.Count
Set Application.Printer = Application.Printers(lPrinters)
Set prtDefault = Application.Printer
Select Case prtDefault.DeviceName
Case Is = sPrinterName
lPrinterCurrent = lPrinters
Case Is = "PDFCreator"
lPrinterPDF = lPrinters
Case Else
'do nothing
End Select
Next lPrinters
On Error GoTo 0
'Change the default printer
Set Application.Printer = Application.Printers(lPrinterPDF)
Set prtDefault = Application.Printer
'Start PFF Creator
Set pdfjob = New PDFCreator.clsPDFCreator
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print the document to PDF
Dim where As String
where = "[nodecotizacion]=" & Me.nodecotizacion
DoCmd.OpenReport sReportName, acNormal, , where
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose
'Reset the (original) default printer and release PDF Creator
Set Application.Printer = Application.Printers(lPrinterCurrent)
Set pdfjob = Nothing
'****** AQUI EMPIEZA LA PARTE DEL CORREO******
On Error GoTo sol_err
'Definimos las variables
Dim mailA As String
'Cogemos los valores que hemos indicado en el formulario
mailA = Me.email.Value
'Creamos una instancia de Outlook
Dim Olk As Outlook.Application
Set Olk = CreateObject("Outlook.Application")
'Creamos un nuevo mensaje de Outlook
Dim OlkMsg As Outlook.MailItem
Set OlkMsg = Olk.CreateItem(olMailItem)
'Creamos la información del mail
With OlkMsg
'Definimos los elementos del mail
Dim OlkDestinatario As Outlook.Recipient
Dim OlkAdjunto As Outlook.Attachment
'Inicializamos los elementos del mail
Set OlkDestinatario = .Recipients.Add(mailA)
OlkDestinatario.Type = olTo
'Comprobamos que exista el archivo que vamos a adjuntar
If Not IsMissing(sPDFPath & sPDFName) Then
Set OlkAdjunto = .Attachments.Add(sPDFPath & sPDFName)
End If
'Añadimos los elementos Asunto y Mensaje
.Subject = "PRESUPUESTO No." & Me.nodecotizacion & "-" & Format(Date, "dd.mm.yy")
.Body = "Buen día " & Me.contactos & "Por este conducto le saludo y le hago el siguiente presupuesto en Archivo Adjunto."
'Abrimos el mail en vez de envia por si hay que agregarle algo si lo envias es con .send
.Save
.Display
End With
Salida:
Exit Sub
sol_err:
MsgBox Err.Number & ": " & Err.Description
'AQUI EMPIEZA EL CÓDIGO PARA CERRAR EL FORMULARIO SIN PREGUNTAR NI CONFIRMAR
rst.Close
Set rst = Nothing
DoCmd.Close acForm, "cotización"
End Sub

Y aun así no me jala que podría ponerle? Por tu atención muchas gracias

Respuesta
1

Pon esta parte:

'aquí empieza el código para cerrar el formulario sin preguntar ni confirmar
Rst. Close
Set rst = Nothing
DoCmd. Close acForm, "cotización"

Después de la etiqueta Salida

Disculpa mi ignorancia, cual etiqueta salida?

así??

Abrimos el mail en vez de envía por si hay que agregarle algo si lo envías es con .send
.Sabe
.Display
End With
Salida:

rst.Close
Set rst = Nothing
DoCmd.Close acForm, "cotización"
End Sub
Exit Sub
sol_err:
MsgBox Err.Number & ": " & Err.Description
'AQUÍ EMPIEZA EL CÓDIGO PARA CERRAR EL FORMULARIO SIN PREGUNTAR NI CONFIRMAR

Me sale 424: se requiere un objeto

Pregunta, porque no me voy a poner a revisar todo el código: ¿Por qué cierras un rst? ¿En algún sitio lo declaras y lo usas?

Si no lo usas en ningún sitio, esas lineas te sobran, y también el End Sub que metes...

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas