Adrian Pinder
12-12-2001, 09:50 PM
Hi, I'm trying to set the value of the Allow Edits property of a form using a macro. The form is called InvertDataSubform1-1, so in the Item field of the Set Value macro action I have entered: [Forms]![InvertDataSubform1-1].[AllowEdits] and in the Expression field I have: True. When this macro is run from within the form (via a command button) I get the error message "The object you referenced in the Visual Basic procedure as an OLE object isn't an OLE object". Any ideas what I'm doing wrong?
Thanks, Adrian.
boblarson
12-19-2001, 02:54 PM
I'm not positive, but I think you can't set the Form's Allow Edits property at runtime via a macro. I think you'd need to use VB code to do so.
On the Event that you want to have fire, select [EventProcedure] from the dropdown list instead of a Macro.
Next, Click on the ... builder button and when the code window opens up, type in this:
Forms!InvertDataSubform1-1.AllowEdits = True
I tested it and it seemed to work okay.
BL
hth
Adrian Pinder
12-19-2001, 07:01 PM
Thanks Bob, a complicating factor is that the form whose property I'm trying to alter is a subform which is always shown in datasheet view. In datasheet view I can't show a button of course, so I was trying to put the button on the mainform (within which InvertDataSubform1-1 is embedded). Using your code I get another error message saying that the database cannot find InvertDataSubform1-1. I suppose this is because the button is on the main form not the subform? Actually I have found a good enough work around solution by using a hot key to run the macro which works fine so long as the hotkey is used while the relevant form is the active one.
Thanks again for your help and happy holidays.
boblarson
12-19-2001, 10:51 PM
I believe that if you reference your subform directly THROUGH the main form you should be okay.
so in other words:
Forms!MyMainFormName!MySubFormName.AllowEdits=TRUE
You might try that. And it may require you to set the focus on the subform first before doing the allow edits.
Forms!MyMainFormName!MySubFormName.SetFocus
Forms!MyMainFormName!MySubFormName.AllowEdits=TRUE
one of those really should work. Good luck.
BL
hth
Adrian Pinder
12-20-2001, 05:22 PM
Hi Bob, thanks for the latest advice. I'm afraid it didn't work, but it did put me on the right track. With your code I kept getting the error message 'cannot find field InvertDataSubform1-1' i.e. the database thought that the subform was a field in the mainform. I figured this meant I needed to use square brackets somewhere. Anyway, I eventually got the code by using the expression builder and copied that into the code builder. So, with the button on the mainform, the correct code is simply:
[MySubFormName].Form.AllowEdits = True
Thanks for your help though, it did put me on the right track.
Adrian.