Whats wrong with this code?

rodvaN

Registered User.
Local time
Today, 13:25
Joined
May 20, 2009
Messages
92
Hello.. Well I got a product picking with a checkbox.. when I click it.. if another checkbox from the record is marked as "blocked" then it would ask if you really want to pick that product.. If dont it will Undo. But if yes it will mark a field with a textbox content and checkbox another field inside record.
It works when the product its not "blocked" but when it is, it will display the question but it will not mark and writte the field.
Check it out, maybe its not "Me" or it has to be a "currentrecord" or doin it via SQL.
S.O.S

Code:
Private Sub SalidaAlmacen_Click()
        If muestreo = True Then
        respuesta = MsgBox("Este Material esta almacenado como MUESTREADO... ¿Desea Embarcarlo?", vbQuestion + vbYesNo, "buhorus: ¿Desea Embarcar Material MUESTREADO?")
        If respuesta = vbNo Then Me.Undo
        Exit Sub
        End If
        If respuesta = vbYes Then
           Me!SalidaNum = Forms!SALIDASarmar!("[SalidaAuto]").Value
            Me!EnAlmacen = False
            Me.Requery
            Forms!SALIDASarmar!SALIDASderechasubform.Requery
        Exit Sub
        End If
    Me!SalidaNum = Forms!SALIDASarmar!("[SalidaAuto]").Value
    Me!EnAlmacen = False
    Me.Requery
    Forms!SALIDASarmar!SALIDASderechasubform.Requery
End Sub
 
Properly indented this is what your procedure looks like. Is that what you wanted?
Code:
Private Sub SalidaAlmacen_Click()
   If muestreo = True Then
      respuesta = MsgBox("Este Material esta almacenado como MUESTREADO... ¿Desea Embarcarlo?", vbQuestion + vbYesNo, "buhorus: ¿Desea Embarcar Material MUESTREADO?")
      If respuesta = vbNo Then Me.Undo
      Exit Sub
   End If
   If respuesta = vbYes Then
      Me!SalidaNum = Forms!SALIDASarmar!("[SalidaAuto]").Value
      Me!EnAlmacen = False
      Me.Requery
      Forms!SALIDASarmar!SALIDASderechasubform.Requery
      Exit Sub
   End If
   Me!SalidaNum = Forms!SALIDASarmar!("[SalidaAuto]").Value
   Me!EnAlmacen = False
   Me.Requery
   Forms!SALIDASarmar!SALIDASderechasubform.Requery
End Sub
 
If you look at these lines and the way they are presented

Code:
      If respuesta = vbNo Then Me.Undo
      Exit Sub

Line one will only execute the Undo if response was vbNo. However no matter whether the user selects Yes or No the Exit sub on the second line will always be executed. If you only want it to exit if the user select No then it should appear as such

Code:
      If respuesta = vbNo Then 
         Me.Undo
         Exit sub
      End If

The following code is exactly the same as the indented code for Respuesta = vbYes

Code:
   Me!SalidaNum = Forms!SALIDASarmar!("[SalidaAuto]").Value
   Me!EnAlmacen = False
   Me.Requery
   Forms!SALIDASarmar!SALIDASderechasubform.Requery

And I suspect it will never ever get thart far in the sub routine as you have covered all angles in your exit subs

To code this correctly you need to expand the second set of code to look like this

Code:
      If respuesta = vbNo Then 
         Me.Undo
         Exit sub
      Else
          Me!SalidaNum = Forms!SALIDASarmar!("[SalidaAuto]").Value
          Me!EnAlmacen = False
          Me.Requery
          Forms!SALIDASarmar!SALIDASderechasubform.Requery
      End If

Then you can remove the redundant code from the bottom of your sub.
David
 

Users who are viewing this thread

Back
Top Bottom