Function SetformState()
Dim State As AlbaranState
If (Me.cboIDEstado.Value = 1) Then
State = New_Albaran
ElseIf (Me.cboIDEstado.Value = 2) Then
State = InProcess_Albaran
ElseIf (Me.cboIDEstado.Value = 3) Then
State = Closed_Albaran
End If
Me.frmSubAlbaran.Locked = (State = Closed_Albaran)
Me.txtAlbaranNumero.Enabled = (State = New_Albaran) Or (State = InProcess_Albaran)
Me.txtFecha.Enabled = (State = New_Albaran) Or (State = InProcess_Albaran)
Me.cboCliente.Enabled = (State = New_Albaran) Or (State = InProcess_Albaran)
Me.cmdExportar.Enabled = (State = New_Albaran) Or (State = InProcess_Albaran)
Me.cmdEliminarPieza.Enabled = (State = New_Albaran) Or (State = InProcess_Albaran)
Me.cmdfrmPedidoDetalleAlbaran.Enabled = (State = New_Albaran) Or (State = InProcess_Albaran)
End Function
Private Sub cmdExportar_Click()
Dim salbaran As Long
Dim datepedido As String
Dim prompt As String
Dim response As Integer
Dim Ssql As String
Dim StrAlbaran As Long
Dim AlbaranNum As Long
prompt = "Estas seguro que quieres actualizar el Stock y crear el Albarán " & Me.txtAlbaranNumero
If IsNull(Me.txtDsumtotal) Then
MsgBox "Introduce Piezas en el Albarán", vbExclamation + vbOKOnly
ElseIf IsNull(Me.txtAlbaranID) Then
MsgBox "Introduce Número de Albarán", vbExclamation + vbOKOnly
Else
response = MsgBox(prompt, vbQuestion + vbYesNo + vbDefaultButton2, "Actualizar Stock y Exportar Albarán")
If response = vbYes Then
datepedido = Format(Date, "ddmmyyyy")
salbaran = DLookup("AlbaranNumero", "tblAlbaran", "[AlbaranID]= " & [AlbaranID])
DoCmd.OutputTo acOutputReport, "rptalbaran", acFormatPDF, "c:\users\Alvaro\Desktop\Mecanizados\Albarán" & " " & salbaran & "-" & datepedido & ".pdf", True
StrAlbaran = Me.txtAlbaranID
Ssql = "UPDATE (tblPiezas INNER JOIN tblPedidoDetalle ON tblPiezas.[PiezaID] = tblPedidoDetalle.[PiezaID]) INNER JOIN tblpedidodetallealbaran ON tblPedidoDetalle.[PedidoDetalleID] = tblpedidodetallealbaran.[PedidoDetalleID]" & _
"SET tblPiezas.Stock= [Stock]-[NumeroPiezas]" & _
"WHERE (((tblpedidodetallealbaran.AlbaranID)=" & StrAlbaran & "));"
DoCmd.SetWarnings (0)
DoCmd.RunSQL Ssql
DoCmd.SetWarnings (1)
Me.cboIDEstado.Value = 3
Me.Refresh
[COLOR=Red] DoCmd.RepaintObject acForm, "frmAlbaran"[/COLOR]
MsgBox "El Albarán se ha exportado con exito", vbExclamation + vbOKOnly, "Exportación con exito"
Else
Close
End If
End If