Error 2185 (1 Viewer)

basshead22

Registered User.
Local time
Today, 14:04
Joined
Dec 17, 2013
Messages
52
hello all, I am trying to lock a sub form based on a checkbox on my mainform I was able to get it to lock but when I click on one of the cells of the subform after it's been locked I get error message 2185. Please see pic ! My code is as follows on my mainform (on current) event and I also put it on my check box (afterupdate) control. I know if it's locked no reason to click on the field but just in case they try it I don't want them to get an eerror message.

If Me.FinalizeBx.Value = True Then
Me.tbl_04_insp_Quantities_subform.Enabled = False
Else
Me.tbl_04_insp_Quantities_subform.Enabled = True
End If
 

Attachments

  • 2185 error.jpg
    2185 error.jpg
    63.3 KB · Views: 70

isladogs

MVP / VIP
Local time
Today, 22:04
Joined
Jan 14, 2017
Messages
18,273
You say you want to lock the subform but your code is disabling it instead
That is partly why you get the error - is a control is disabled it can't have the focus

So I would set the focus to another control & change the code to use .Locked as follows:

Code:
Me.NameOfAnotherControl.SetFocus

If Me.FinalizeBx.Value = True Then
      Me.tbl_04_insp_Quantities_subform.Locked = False
Else
      Me.tbl_04_insp_Quantities_subform.Locked = True
End If

With luck no error message from now on...BUT ....

Its always better to fix the cause of an error rather than hide it.
However, you can suppress error messages like this:

Code:
Sub ProcName()

On Error GoTo Err_Handler

   'Your code goes here

Exit_Handler:
    Exit Sub

Err_Handler:
    If err<>2185 Then 'substitute error number to fit your needs
          MsgBox "Error " & Err.Number & " in ProcName procedure : " & vbNewLine & Err.Description
    End If
    Resume Exit_Handler

End Sub
 

basshead22

Registered User.
Local time
Today, 14:04
Joined
Dec 17, 2013
Messages
52
Thank you for the reply!

so I changed the code to locked instead of enabled.

Not sure what other contral name to use to set the focus... a control in my mainform or subform...?

Also the code you wrote to suppress the error where does that go?

Sorry if these are dumb questions I'm not super savy with VB ..
 

isladogs

MVP / VIP
Local time
Today, 22:04
Joined
Jan 14, 2017
Messages
18,273
Not sure what other contral name to use to set the focus... a control in my mainform or subform...?
Main form

Also the code you wrote to suppress the error where does that go?

First check whether you still get the error - I expect not
If you do get an error, better to try & fix it

BUT if you MUST suppress it, then you just combine the two bits of code I gave you in whatever procedure you are locking the subform

Code:
Sub ProcName() <==your procedure name goes here

On Error GoTo Err_Handler

   'Your code goes here
   Me.NameOfAnotherControl.SetFocus

   If Me.FinalizeBx.Value = True Then
          Me.tbl_04_insp_Quantities_subform.Locked = False
   Else
          Me.tbl_04_insp_Quantities_subform.Locked = True
   End If

Exit_Handler:
    Exit Sub

Err_Handler:
    If err<>2185 Then 'substitute error number to fit your needs
          MsgBox "Error " & Err.Number & " in ProcName procedure : " & vbNewLine & Err.Description
    End If
    Resume Exit_Handler

End Sub
 

Users who are viewing this thread

Top Bottom