Solved Run-time error '2101'

tihmir

Registered User.
Local time
Yesterday, 21:52
Joined
May 1, 2018
Messages
257
Hi,
I have a subform with several required comboboxes. I have the following validation code:


Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)  
    If Me.Parent.objectID = "" Or IsNull(Me.Parent.objectID) Then
        MsgBox "Please select an object.", vbInformation, "Аttention!"
        Me.Undo
    End If
   
    If Not Nz(Me.inspectionID, "") = "" And Nz(Me.Date, "") = "" Then
        MsgBox "If you want to continue please enter a 'Date '." & vbCrLf & _
        "Otherwise press  ESC.", vbInformation, "Аttention!"
        Cancel = True
        Exit Sub
    End If
   
    If Not Nz(Me.Date, "") = "" And Nz(Me.inspector, "") = "" Then
        MsgBox "If you want to continue please enter a 'Inspector '." & vbCrLf & _
        "Otherwise press  ESC.", vbInformation, "Аttention!"
        Cancel = True
        Exit Sub
    End If
       
    If Not Nz(Me.inspector, "") = "" And Nz(Me.Type, "") = "" Then
        MsgBox "If you want to continue please enter a 'Type '." & vbCrLf & _
        "Otherwise press  ESC.", vbInformation, "Аttention!"
        Cancel = True
        Exit Sub
    End If
End Sub
Code:
Private Sub cboType_AfterUpdate()
    If Me.Dirty = True Then
       Me.Dirty = False
    End If
   
    If Me.cboType = "PSD" Then
        DoCmd.OpenForm "fm_inspection, , , "[inspectionID]=" & Me.inspectionID
        DoCmd.GoToControl "PSD"
        Exit Sub
    End If
End Sub
When I click on cboType and choose "PSD", without entering a date,
the first part of the code works fine and it shows me -> MsgBox "If you want to continue please enter a 'Inspector'. "Otherwise press ESC.". "Аttention!".
But then when I click "OK", it shows me access error - Run-time error '2101': The setting you entered isn't valid for this property.
What can I do to prevent this access message from coming up!
Thanks
 
Move the record save to the validation successful part of your code.
I suspect that it's trying to save the record in your after update code, but can't because you have cancelled the save.
 
Move the record save to the validation successful part of your code.
I suspect that it's trying to save the record in your after update code, but can't because you have cancelled the save.
I did it! Thank you!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom