Code for setting Forms to open with custom tool bar, menubar and control custom short

M

Minal Shah

Hi,

I have created a Custom Form Toolbar, Custom Form Menubar, Form
Shortcut bar and a Form Control Shortcut Bar.

When I go into the individual forms into properties and set the
toolbar, menubar and shortcut bar options it works.
So since I wanted to do this for a large # of forms I wrote this code.

But something is not right. Can someone help me figure out what is
wrong.

This is my first attempt with writting codes and I have no training,
background or experience with this sort of thing.
So please bear with me if I make silly mistakes.

I have worked 2 nights to get here. Any help is welcomed

CODE.


Public Sub SetFormToolbar()
Dim objFrm As AccessObject, frm As Form, ctl As Control
' Go through every form in the database
For Each objFrm In CurrentProject.AllForms
' Skip fixing any "plain" examples
If Right(objFrm.Name, 5) <> "plain" Then
DoCmd.OpenForm FormName:=objFrm.Name, View:=acDesign, _
WindowMode:=acHidden
' Set a pointer to the form just opened
Set frm = Forms(objFrm.Name)
' Set custom menu and toolbars for the form object
' .. only for primary forms
If Left(frm.Name, 3) = "frm" Then
' Clear any saved filter while we're at it
Forms(frm.Name).Filter = ""
' Set the custom menu bar
Forms(frm.Name).MenuBar = "Custom Form Menu Bar"
' Set the custom toolbar
Forms(frm.Name).Toolbar = "Custom Form Toolbar"
' Set the custom shortcut menu bar
Forms(frm.Name).ShortcutMenuBar = "Form Shortcut Bar"
End If
' Loop through all controls
For Each ctl In frm.Controls
' Skip control types that don't have a ShortcutMenuBar property
If (ctl.ControlType <> acCustomControl) And _
(ctl.ControlType <> acSubform) And _
(ctl.ControlType <> acRectangle) And _
(ctl.ControlType <> acLabel) And _
(ctl.ControlType <> acLine) And _
(ctl.ControlType <> acPageBreak) Then
' Set the custom control shortcut menu
ctl.ShortcutMenuBar = "Form Control Shortcut Bar"
End If
' Close the form
DoCmd.Close acForm, objFrm.Name
' Loop to the next form
' Clean up
Set ctl = Nothing
Set frm = Nothing
Set objFrm = Nothing
End Sub

Thanks
Minal
 
R

Rick Brandt

Minal said:
Hi,

I have created a Custom Form Toolbar, Custom Form Menubar, Form
Shortcut bar and a Form Control Shortcut Bar.

When I go into the individual forms into properties and set the
toolbar, menubar and shortcut bar options it works.
So since I wanted to do this for a large # of forms I wrote this code.

But something is not right. Can someone help me figure out what is
wrong.

You need to be more specific. What does "something is not right" mean? Do you
get an error?

If this was copied directly from your code you have no Next to match up with
your For Each block. Of course the compiler caught that for me. Did it not for
you? You have a comment line that talks about looping to the next form, but no
actual line of code to make that happen.

Public Sub SetFormToolbar()
Dim objFrm As AccessObject, frm As Form, ctl As Control
' Go through every form in the database
For Each objFrm In CurrentProject.AllForms
' Skip fixing any "plain" examples
If Right(objFrm.Name, 5) <> "plain" Then
DoCmd.OpenForm FormName:=objFrm.Name, View:=acDesign, _
WindowMode:=acHidden
' Set a pointer to the form just opened
Set frm = Forms(objFrm.Name)
' Set custom menu and toolbars for the form object
' .. only for primary forms
If Left(frm.Name, 3) = "frm" Then
' Clear any saved filter while we're at it
Forms(frm.Name).Filter = ""
' Set the custom menu bar
Forms(frm.Name).MenuBar = "Custom Form Menu Bar"
' Set the custom toolbar
Forms(frm.Name).Toolbar = "Custom Form Toolbar"
' Set the custom shortcut menu bar
Forms(frm.Name).ShortcutMenuBar = "Form Shortcut Bar"
End If
' Loop through all controls
For Each ctl In frm.Controls
' Skip control types that don't have a ShortcutMenuBar property
If (ctl.ControlType <> acCustomControl) And _
(ctl.ControlType <> acSubform) And _
(ctl.ControlType <> acRectangle) And _
(ctl.ControlType <> acLabel) And _
(ctl.ControlType <> acLine) And _
(ctl.ControlType <> acPageBreak) Then
' Set the custom control shortcut menu
ctl.ShortcutMenuBar = "Form Control Shortcut Bar"
End If
' Close the form
DoCmd.Close acForm, objFrm.Name
' Loop to the next form
' Clean up
Set ctl = Nothing
Set frm = Nothing
Set objFrm = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top