Sub Form Error

acsuser1

Registered User.
Local time
Today, 13:20
Joined
Aug 27, 2014
Messages
16
I'm using a Sub Form_Error and Select Case to look for specific errors. I have two comboboxes and when the error is recognized I have an image display. This works fine when cmbEXEID is scanned incorrectly but does not work when the cmbEquipEXEID is scanned incorrectly. Here is the code I have:
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
    
    Select Case DataErr
    
        Case 2237
         
            imgTryAgain.Visible = True
            Cancel = True
            Me.cmbEXEID.Undo
            Me.cmbEquipID.Undo
                                         
                TWait = Time
                TWait = DateAdd("s", 5, TWait)
                Do Until TNow >= TWait
                    TNow = Time
                Loop
            
            imgTryAgain.Visible = False
                                            
        Case 3314
           Cancel = True
            imgTryAgain.Visible = True
 
    On Error Resume Next
    
    End Select
    
    Response = acDataErrContinue
    
            
End Sub
 
What doesn't work? What error message do you get?

By the way, a loop will zoom through 5 in micro seconds, so that loop isn't really doing much. If you want 5 seconds you should use Now()
 
What's not working is the image displaying when the second combobox is scanned incorrectly. The user will only have a scan gun. They scan their badge for the cmbEXEID box and if their badge is not recognized then the image Try Again will display for 5 seconds and they can scan a valid badge. The focus then goes to the cmbEquipID where they scan the equipment they will be using. In error testing I scan an invalid equipment barcode and want the image Try Again to display again but it does not. The delay works but the image does not show.

Thank you for the info on the time. This is my first time using a delay.
 
If you try again then it means that there's something else the matter. The barcode, the scanner or something else. Your focus should be on the scanning process itself.

Sorry, I actually meant Time() instead of Now().
 
I'm not sure what you mean by "Your focus should be on the scanning process itself". Can you explain?

I have tried the NotInList Event for both of these comboboxes but have not been successful so when I got to work on the Form On Error I was excited about that.
 
What's not working is the image displaying when the second combobox is scanned incorrectly.
I may have read that wrong. The image is not getting displayed because the error it's encountering is not 2237 or it may not even be a Form error. Step through your code and see what error message it generates and where.
 
I checked to see what the error is when scanning for the equipment and it is 2237.

When I scan an invalid badge ID the "Try Again" form appears, the txtEXEID clears, and the delay happens for about 3 seconds. Then I scan a valid badge ID and the focus moves to Scan Equipment.

When I scan an invalid equipment # the "Try Again" form does not appear but the txtEquipID does clear and the delay happens. I need the Try Again form to appear with each error so that the user will be prompted to try again. (I still need to make the time suggestion in my code that you offered last week.) Thank you

Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
    MsgBox DataErr
    
    Select Case DataErr
    
        Case 2237
            'Display TryAgain form and clear combobox
            imgTryAgain.Visible = True
            Cancel = True
            Me.cmbEXEID.Undo
            Me.cmbEquipID.Undo
            
                TWait = Time
                TWait = DateAdd("s", 3, TWait)
                Do Until TNow >= TWait
                    TNow = Time
                Loop
                
                imgTryAgain.Visible = False
                     
        Case 3314
            imgTryAgain.Visible = True
            Cancel = True
            Me.cmbEXEID.Undo
            Me.cmbEquipID.Undo
            
                TWait = Time
                TWait = DateAdd("s", 3, TWait)
                Do Until TNow >= TWait
                    TNow = Time
                Loop
                imgTryAgain.Visible = False
        
        Case 2169
            imgTryAgain.Visible = True
            Cancel = True
            Me.cmbEXEID.Undo
            Me.cmbEquipID.Undo
                
                TWait = Time
                TWait = DateAdd("s", 3, TWait)
                Do Until TNow >= TWait
                    TNow = Time
                Loop
                imgTryAgain.Visible = False
                                            
    On Error Resume Next
    End Select
    Response = acDataErrContinue
            
End Sub
 
..
When I scan an invalid equipment # the "Try Again" form does not appear but the txtEquipID does clear and the delay happens. I need the Try Again form to appear with each error so that the user will be prompted to try again.
Could it be because the "Try Again" form is hidden behind something else?
Why do you have a "On Error Resume Next" as 3. last line in your code, (comment it out or delete it)?
Have you tried to step through you code, (place a breakpoint in your code)?
 
I'm new to coding in Access. I was following the template of the Sub Form_Error and that is why On Error Resume Next is in the code. I will remove it all together if I don't need it. As for the form not displaying, I stating for it to be visible and then after the delay for it to not be visible. Can you explain more about what you mean by it might be hidden behind something?
 
... and that is why On Error Resume Next is in the code. I will remove it all together if I don't need it.
If you don't comment it out or delete the line with "On Error Resume Next", you'll not notice if the code raise an error, because it is going to the next line.
The "On Error Resume Next" most evil error handling it gives! :mad:

... Can you explain more about what you mean by it might be hidden behind something?
It can be hidden behind an other form.
Here is a description how to set a breakpoint and how to use it.
http://www.techonthenet.com/access/tutorials/vbadebug/debug02.php

http://office.microsoft.com/en-us/access-help/HV080755512.aspx
 
Got it working! Thank you vbaInet and JHB. Appreciate your help.

Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
    'MsgBox DataErr
    'Display TryAgain image and clear combobox with focus back in combobox
    Select Case DataErr
    
        Case 2237
                
            imgTryAgain.Visible = True
            Me.cmbEXEID.Undo
            Me.cmbEquipID.Undo
            
                'Cause a delay
                TWait = Time()
                TWait = DateAdd("s", 2, TWait)
                Do Until TNow >= TWait
                    TNow = Time()
                    DoEvents
                Loop
                
                                 
        Case 3314
            imgTryAgain.Visible = True
            Cancel = True
            Me.cmbEXEID.Undo
            Me.cmbEquipID.Undo
            
                'Cause a delay
                TWait = Time()
                TWait = DateAdd("s", 2, TWait)
                Do Until TNow >= TWait
                    TNow = Time()
                    DoEvents
                Loop
           
        
        Case 2169
            imgTryAgain.Visible = True
            Cancel = True
            Me.cmbEXEID.Undo
            Me.cmbEquipID.Undo
                
                'Cause a delay
                TWait = Time()
                TWait = DateAdd("s", 2, TWait)
                Do Until TNow >= TWait
                    TNow = Time()
                    DoEvents
                Loop
    
    End Select
    'Ignore the default error message
    Response = acDataErrContinue
                         
End Sub
 
Good you got it to work, but what was the problem? :)
 
Adding DoEvents is what did the trick. Still being new to the coding side of Access I am not really sure why that fixed it except to say it returns control. Is this correct or will you explain further?
 

Users who are viewing this thread

Back
Top Bottom