Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visible property on a control on form 2

Status
Not open for further replies.

cfvcf

Technical User
Nov 8, 2007
77
US
I have a main menu that will display a dropdown control if they select a button on that form. I have the following code when the menu form opens, lost_focus, and loads:
combo_Orgs_and_Accounts.Visible = False
When they click on a button it displays the dropdown control. All of that works fine. When they click on an item in the dropdown, it goes to another form - that works. When they click on the "go to new menu button" I coded
Private Sub btnClose_Click()
On Error GoTo btnClose_Click_Err
DoCmd.Echo True, ""
DoCmd.Close , ""
DoCmd.OpenForm "frm_New_Menu", acNormal, "", "", , acNormal
btnClose_Click_Exit:
Exit Sub

btnClose_Click_Err:
MsgBox Error$
Resume btnClose_Click_Exit
End Sub

But when the "new menu form" opens, the dropdown displays as well as the label for the dropdown. What other event should I use to make sure the dropdown does not display.

Also, does the "label" also only display when the control does and do I need to code to make that property not visible?
Thanks for any help!
 
well, if you need to have the menu display on a form one time, you can set a public variable as a flag...

Code:
public flag as boolean

if (flag = false) then
    menu.visible = false
else
    menu.visible = true
end if
 
The problem I'm having with this is that the control (the dropdown that I want to be invisible the next time the form is open) was the last field that had focus when it opened the next form. So I set this public flag to false when they leave that next form, thinking I could check it when the form reopens. But then the dropdown still has focus somehow. And it won't let me change the .visible to False while it has focus. How do you "lose focus" on a control when the form activates?
Thanks. Appreciate your help.
 
Set the focus to a diff control, like the button or something.

Also look in the TAB ORDER of the form--is the cbo box the first item listed? That will make it have the focus when the form is opened. You can change the tab order, of if you don't care to tab into that control, set AUTO TAB or whatever property it is to FALSE or NO.

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
well, if focus is the problem, on form open, have your code check your flag variable.

if flag = false, diffControl.setfocus

else dropdown.setfocus
 
sorry for posting in fragments.

the code will look similar to this

Code:
if (flag = false) then
    somethingThatIsntDropDown.Setfocus
    menu.visible = false
else
    dropDown.setfocus
    menu.visible = true
end if
 
Believe me, I don't mind the posting in fragments, and I appreciate all of your help and others. But I'm having a problem in setting focus on a diff control. I tried to do that on a button and on a date on the form and I get an error "MS can't move focus to the control (which ever).." Guess I'm missing something.

Below is my code for the load event:
Private Sub Form_Load()
MsgBox "new menu load"
MsgBox combo_orgs_visible 'shows false
combo_Orgs_and_Accounts.Visible = False 'control doesn't display
End Sub

Below is the code for when someone clicks on the dropdown value:
Private Sub combo_Orgs_and_Accounts_Click()
On Error GoTo combo_Orgs_and_Accounts_Click_Err
DoCmd.OpenForm "frm_Organizations_and_Accounts", acNormal, "", _
"[tbl_Orgs]![OrgName]=[Forms]![frm_New_Menu]![combo_Orgs_and_Accounts]", , acNormal
DoCmd.Maximize
combo_Orgs_and_Accounts_Click_Exit:
Exit Sub

Below is my code for the form activate event:
Private Sub Form_Activate()
MsgBox "new menu form activate"
MsgBox "btn_Add_New_Inst setfocus"
'btn_Add_New_Inst.SetFocus
combo_Orgs_and_Accounts.Visible = False
End Sub
I got the error "can't move focus to control btn_Add_New_Inst" when 'btn_Add_New_Inst.SetFocus was not commented out.

Then I got the error "cannot hide a control that has focus" for the line "combo_Orgs_and_Accounts.Visible = False" which is the dropdown?

I hope I'm being clear.
Thanks again!
 
hmm - well, I know I try to get around these problems by trying to spread out the code a bit. Put the combo_Orgs_and_Accounts.Visible = False code into a public function. When you go back to set your flag variable on exit, then change the focus or visibility of Orgs_and_Accounts.
 
Ok, I found out what my problem was. I was not able to setfocus on a button, that was actually just a jpg image but I had events on the image that acted like a button. So when I added a button and added the jpg picture to it as well as the events, I was then able to set focus to the button and change the .visible = false to the dropdown I wanted to hide. Interesting.

But thanks for all your help, your code suggestions were all good and would have worked if I hadn't added the jpg-picture the way I did for the button.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top