I am trying to use an IF statement to enable/disable command buttons; however, I get the following error message "Run Time Error '424': Object Required". The "cmdDeptStoresMC.Enabled=True" is highlighted in yellow when I run the code. Please assist. Below is my code:

Sub Check_AccessRights()
Dim X As String
Dim Y As String
X = EssVCell(Null, "Year Total", "MC", "Business Type", "Accounts", "Departments")
Y = EssVCell(Null, "Year Total", "OR", "Business Type", "Accounts", "Departments")
If X = "#No Access" Then
cmdDeptStoresMC.Enabled = False
cmdRetailStoresMC.Enabled = False
Else
cmdDeptStoresMC.Enabled = True
cmdRetailStoresMC.Enabled = True
End If

If Y = "#No Access" Then
cmdDeptStoresOR.Enabled = False
cmdRetailStoresOR.Enabled = False
Else
cmdDeptStoresOR.Enabled = True
cmdRetailStoresOR.Enabled = True
End If

End Sub

I agree with Comatose. VB can't find a command button named "cmdDeptStoresMC". Either the command button name is mis-spelt, or the form which contains it is not loaded in memory.

Are you sure the command button is named properly? Maybe attach the entire project as a zip?

Comatose,
My command buttons are named correctly. I am attaching my excel file with the VBA code. Please review and Advise. Thanks a lot for your help.

Hello again,

No offence but I don't download anything to my computer unless I have to. However run time error 424 on my version of VB says "form not found". Please check the form that has the command button on you were refering to is in memory. If the form has not been loaded, or has been unloaded before the code referrs to it you will get the message you have posted about. VB cannot find the command button. Maybe your code (to do with one form) is referring to a command button on another form. If that is so then I'll have to have a think about it.

Regards.

Referencing the sheet name before the command buttons resolved the problem. Thanks anyway.

Referencing the sheet name (i.e form) re-loads the form putting the command button in memory. The command button's form was not in memory therefore the button was not there as far as vb could find. You should note that VB is not always correct and I (and many others) have had similar problems where then answer is far more more "weird". So 98 times out of 100 the VB query is right. When it is the other 2 your hair starts falling out!!

Cheers.

Hi, the error may occur when the Microsoft Access Object Library is not referenced, I suggest you trying edit the registry and reinstall Microsoft Office. Visit for more: How To Fix Runtime Error 424

Hope this information is helpful for you.
Regards,
Aron

This article has been dead for over six months. Start a new discussion instead.