Solved

Make Command button visible or not

Posted on 2004-10-05
6
492 Views
Last Modified: 2012-05-05
Hi All,

Hopefully this is an easy one.

I have a main menu form (the Switchboard).
On that form is a command button (cmdImport) that is not visible on form open.
When you double-click the logo graphic (imgLogo), the cmdImport button is visible.
When you click the command button it takes you to another form (one for importing records)
After you have finished importing records, you click and exit command button and you return to the main menu (Switchboard)
The problem is, when you return to the main menu the cmdImport button is still visible... I'd like for it to be invisible again... like it was on form open.

Here's some of my code...

----------On Open - main menu form-------------------------------------------------
Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.

    ' Minimize the database window.
    'DoCmd.SelectObject acForm, "Switchboard", True
    'DoCmd.Hide

    ' Move to the switchboard page that is marked as the default.
    Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
    Me.FilterOn = True
    cmdImport.Visible = False
End Sub

-----------On Double-Click - main menu form ---------------------------------------
Private Sub imgLogo_DblClick(Cancel As Integer)
    cmdImport.Visible = True
End Sub

-----------On Open - import form ----------------------------------------------------
Private Sub Form_Open(Cancel As Integer)
    If IsLoaded("Switchboard") Then
        [Forms]![Switchboard].Visible = False
    End If
End Sub
-----------On Close - import form ----------------------------------------------------
Private Sub Form_Close()
    If IsLoaded("Switchboard") Then
        [Forms]![Switchboard].Visible = True
    End If
End Sub

I'm assuming I need to put "cmdImport.Visible = False"
Somewhere, but I can't figure out under what event.. and on which form.

Any ideas?

TIA,
Die-Tech

0
Comment
Question by:Die-Tech
  • 3
  • 2
6 Comments
 
LVL 36

Accepted Solution

by:
SidFishes earned 500 total points
ID: 12229976
just put

forms!yourFormNAme!cmdImport.Visible = False

at the  end of your import procedure or in the exit_click event of your import form
0
 
LVL 10

Expert Comment

by:ALaRiva
ID: 12229988
I'd say to keep with your logic flow, you have two options,

Option 1 you can put it under the Click Event of the cmdImport
---For this option put it as the last line of code in the event----

Option 2 you can put it under the Close Event of the Import Form


HTH

-Anthony
0
 
LVL 4

Author Comment

by:Die-Tech
ID: 12230130
Ok.. when I do that I get the following error message.

You can't hide a control that has the focus.

Does this mean the cmdImport button on the Switchboard form had the focus (because we just clicked it to open the import form) and when we go back to the Switchboard the cmdImport button still has the focus so you can't make it invisible?

If that's right, I guess I need to change the focus on the Switchboard form to something other than the cmdImport button after you click the cmdImport button and before it opens the import form.

0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 4

Author Comment

by:Die-Tech
ID: 12230207
SidFishes,

I was able to get it working.

I put the following in the cmdImport_click just before it opens the Import form
    Option1.SetFocus

Now when I come back to the Switchboard from the Import form, I don't get any errors and the cmdImport button is invisible.

THanks,
Die-Tech
0
 
LVL 10

Expert Comment

by:ALaRiva
ID: 12230234
Oops, Sorry about that, you'll need to put the code in the close event of the Import Form.

-----------On Close - import form ----------------------------------------------------
Private Sub Form_Close()
    If IsLoaded("Switchboard") Then
        [Forms]![Switchboard].Visible = True
    End If
    Forms!Switchboard!cmdImport.Visible = False
End Sub


I have no idea why I was trying to offer putting it in the Click Event of the button itself.

HTH

-Anthony
0
 
LVL 4

Author Comment

by:Die-Tech
ID: 12230376
ALaRiva,

I tried what you mentioned above and got the same error message
"You can't hide a control that has the focus."

I think the problem is the cmdImport button had the focus when we left the Switchboard to go to the Import form.
After leaving the Import form, going back to the Switchboard the cmdImport button still has the focus so it won't let the control be invisible.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now