Results 1 to 4 of 4
  1. #1
    Waubain is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    25

    Creating only one menu that has two states

    A new responsibily assigned is to oversee all the projects our department. Nothing formal in the past. I created a Access db with a main menu that links to forms and predeveloped reports. Users wanted to be able to see only their information as well as globally. I created a button on the menu to "personalize" their menu. This opened a form where they choose their name from a combobox. This action set a temporary variable with their name[UserName] and opened a second identical menu to the main menu. All further queries and reports used the temp var as the query. In the corner of their personalize menu was a button that stated "globalize". This removed the temp var and opend the original Main Menu. This works, but I have two identical menus, queries,etc and as I expand I do double work.
    My question is how could this be done with only one menu, etc? I would like the globalize/personalize button (btnStatus) to change captions and state when clicked. I arrived at the below by logic only and no knowledge was involved. The problem with being a absolute beginner is you don't know what you don't know.

    Sorry I mixed the little code I know wth English

    Code:
     
    MainMenu (OnLoad) loads in global state
    btnStatus.caption = Personalized.
    btnStatus OnClick
    Opens ChooseNameForm    ‘employee picks name from combobox [cboSelectName]
     In combobox AfterUpdate property  
     start macro Action: SetTempVar   Argument: UserName,    [Screen].[ActiveControl].[Value]
     btnOK (onClick) go back to mainmenu
     change btnStatus.caption = Globalize
    Now if they clicked the button again the reverse would happen and the TempVar UserName would be removed. 
    How would this change my queries? Currently "EmployeeName"=[TempVars]![UserName] in the personalized queries and the Criteria is left blank in the second globalize query.
    Any help would be much appreciated.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    I have not looked at your material in detail. Here are a few things that you might consider.
    A variable with data type Boolean has only 2 states - Yes/No, On/Off...
    So if you need something with only 2 states, it would seem that a Boolean variable to control some logic would be a good start.

    The other thing about a Boolean variable is that to change it froom its current state to the other state you can say

    myBoolVar = Not myBoolVar which basically says, whatever myBoolVar is, make it the other. And each time through this assignment it will "flip" the value.

    Good luck with your project.

    I don't have acc2007, and I haven't worked much with macros.

  3. #3
    Waubain is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    25
    I was able to get this to work. Unfortunately the queries as suspected all broke...new thread.

    Code:
     
    Option Compare Database
    Option Explicit
    Dim blnOnButtonClicked As Boolean
    Private Sub btnToggle_Click()
    On Error GoTo Error_Routine
    If Me.btnToggle.Caption = "Personalize" Then
        Me.btnToggle.Caption = "Globalize"
        blnOnButtonClicked = True
        DoCmd.OpenForm "WhoAmI"
    ElseIf Me.btnToggle.Caption = "Globalize" Then
        Me.btnToggle.Caption = "Personalize"
        blnOnButtonClicked = False
        DoCmd.RunMacro "Globalize"
    End If
    Exit_Continue:
        Exit Sub
    Error_Routine:
        MsgBox "Error# " & Err.Number & " " & Err.Description
        Resume Exit_Continue
    End Sub

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    In a separate module put in this code ( Global makes it available when your Form is opened)

    Global blnOnButtonClicked As Boolean
    In the form's private module
    Private Sub btnToggle_Click()
    On Error GoTo Error_Routine
    Debug.Print "entered Button OnClick - " & "blnOnButtonClicked is now " & blnOnButtonClicked & " " & Now
    blnOnButtonClicked = Not blnOnButtonClicked
    Debug.Print "blnOnButtonClicked is now " & blnOnButtonClicked & " " & Now
    If blnOnButtonClicked = True Then
    Me.btnToggle.Caption = "Globalize"
    ' DoCmd.OpenForm "WhoAmI"
    Else
    Me.btnToggle.Caption = "Personalize"
    ' DoCmd.RunMacro "Globalize"
    End If
    Exit_Continue:
    Exit Sub
    Error_Routine:
    MsgBox "Error# " & Err.number & " " & Err.Description
    Resume Exit_Continue
    End Sub
    and when this form is first opened, set the value
    of the boolean flag to True

    blnOnButtonClicked = True

    Private Sub Form_Open(Cancel As Integer)

    blnOnButtonClicked = True
    Debug.Print "blnOnButtonClicked is " & blnOnButtonClicked & " form Open " & Now
    Me.btnToggle.Caption = "Globalize"
    End Sub
    I have included some debug.print statements to show the value of certain variables at different points in the process. You can comment these out.

    I commented out your macro stuff and a OpenForm. You can adjust as required.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. need to unhide my top menu bar
    By techexpressinc in forum Forms
    Replies: 1
    Last Post: 06-08-2010, 07:05 AM
  2. Menu Bar
    By graviz in forum Forms
    Replies: 0
    Last Post: 02-23-2010, 09:04 AM
  3. States Table & PK
    By mastromb in forum Database Design
    Replies: 8
    Last Post: 01-01-2010, 11:25 AM
  4. customized menu bar
    By marianne in forum Access
    Replies: 13
    Last Post: 04-12-2009, 09:47 PM
  5. How about creating a drop down menu in a report?
    By beastmaster in forum Access
    Replies: 2
    Last Post: 12-29-2005, 01:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums