John wrote:
How can I create a toggle button on a toolbar that would enable/disable
editing on the current form?
I'll assume you know how to create a custom menu and menu item. If not
write back and I'll write the "prequel" to the following! 8)
Write a function and save in a standard module. The function is as
written in air code following my comments below.
Make the function the on action item for the menu item, ie, for the
following, you need to enter:
=fToggleEditNamedForm(Forms!MyForm)
The Menu item can be called "Edit Form" or something and will be
ticked/depressed when in edit mode and unticked/not depressed when not
in edit mode. The "State" property use in my code below will add a tick
beside the menu item if this is a tool bar (WARNING, if you have a
picture for the item, the tick will NOT show) or depressed/not depressed
if this is a menu bar.
Alternately, instead of Forms!MyForm as an argument, you may choose to
use Screen.ActiveForm, but make certain when this menu item is used,
that the correct form is displayed!
Here's the function (air code). Note that the item in the commandbars
reference is the number of the control from the left. You won't need
any references set up for the items in the function, as everything runs
fom vba just fine:
Function fToggleEditMyForm(f as Access.Form)
'This function toggles the allowedit property of the form
'passed in the argument, f.
'
'f is the form being toggled.
'I realize the following could be achieve in less lines
'using the NOT operator, but I like this sort of thing as
'I find it easier to figure out WTF I was doing when
'I look at the code later
'Assume menu control is number 3 (arbitrary - Your
'mileage may vary)
if commandbars("mnuCustomMenuName").controls(3).State = true then
'Control is currently ticked/depressed (state property), so
'turn it OFF and turn allowedits OFF.
commandbars("mnuCustomMenuName").controls(3).State = False
f.Allowedits = false
else
'Control is currently not ticked/depressed (state property), so
'turn it ON and turn allowedits ON.
commandbars("mnuCustomMenuName").controls(3).State = True
f.Allowedits = True
end if
Exit_Proc:
Exit function
Err_Proc:
'This is pretty fool proof, so I don't include any error handling
End Function
--
Tim
http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me