Dlookup does not work :(

AlvaroCity

Registered User.
Local time
Today, 08:02
Joined
Jul 16, 2016
Messages
70
Hi everyone.

I have my db finished but after using it on different computers one of the Dlookup functions stopped working and I don't know why. Basically this to create a pdf along, change the status and decrease the stock.

Code:
salbaran = DLookup("[AlbaranNumero]", "tblAlbaran", "[AlbaranID]= " & [AlbaranID])

I have been trying to find out what's wrong but I can't find the solution.
I will also post the whole code just in case you can guys see something.
I will appreciate all your help. thank you so much. (It is in Spanish.. sorry)
Code:
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
    
    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(Me.txtFecha, "ddmmyyyy")
        
        salbaran = DLookup("[AlbaranNumero]", "tblAlbaran", "[AlbaranID]= " & [AlbaranID])
        
        DoCmd.OutputTo acOutputReport, "rptalbaran", acFormatPDF, "C:\Users\Mecaly\OneDrive - Mecaly\MECALY\Albaranes\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
        
        Call SetformState
        
        Me.Refresh
        MsgBox "El Albarán se ha exportado con exito", vbExclamation + vbOKOnly, "Exportación con exito"
        
        Else
        
        Close
        
        End If
        
    End If
    
  End Sub
 
My guess is that VBA has no idea what you are talking about when you reference [AlbaranID]. I see no where else in the code where you either declare it or assign it a value.
 
Is the part in red

"[AlbaranID]= " & [AlbaranID]

a Control on the Form? If so, try

"[AlbaranID]= " & Me.AlbaranID

Also note that this syntax is only correct if AlbaranID

is a Number. If it's Text, it would be

"[AlbaranID]= '" & Me.AlbaranID & "'"

Linq ;0)>
 
Hi everyone.

I have my db finished but after using it on different computers one of the Dlookup functions stopped working and I don't know why. Basically this to create a pdf along, change the status and decrease the stock.

Code:
salbaran = DLookup("[AlbaranNumero]", "tblAlbaran", "[AlbaranID]= " & [AlbaranID])
I have been trying to find out what's wrong but I can't find the solution.
I will also post the whole code just in case you can guys see something.
I will appreciate all your help. thank you so much. (It is in Spanish.. sorry)
Code:
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
    
    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(Me.txtFecha, "ddmmyyyy")
        
        salbaran = DLookup("[AlbaranNumero]", "tblAlbaran", "[AlbaranID]= " & [AlbaranID])
        
        DoCmd.OutputTo acOutputReport, "rptalbaran", acFormatPDF, "C:\Users\Mecaly\OneDrive - Mecaly\MECALY\Albaranes\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
        
        Call SetformState
        
        Me.Refresh
        MsgBox "El Albarán se ha exportado con exito", vbExclamation + vbOKOnly, "Exportación con exito"
        
        Else
        
        Close
        
        End If
        
    End If
    
  End Sub

Hola

Chequea el DatePedido format:

it should be datepedido = Format(Me.txtFecha, "dd/mm/yyyy")
 

Users who are viewing this thread

Back
Top Bottom