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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding a command button

Status
Not open for further replies.

neeko1226

MIS
Jul 24, 2003
82
US
I have a Access 97 database that was built by someone else a long time ago. The main form has several command buttons that allow users to move through the database. The person that developed the system used macros to open the new forms called from the on click event of the command buttons. The command buttons are also named with spaces and no prefix to identify them as such ("open main cra form from switchboard"). This name ("open main cra form from switchboard") is also the name of the macro the command button is calling on click.

My issue is, I'm attempting to hide a command button from a user that has been known to enter invalid data. I have the following vba code running on open of the main form, but the command button is still visible.

Set rs = db.OpenRecordset("Select CDMID from tbl_AuthorizedUsers where CitrixID = '" & ID & "' or NetworkID = '" & ID & "' ")

If rs!cdmid = 10 Then

Me.open_main_cra_form_from_switchboard.Visible = False

End IF

Note the cdmid I'm currently using is my own for testing. Also, when I used the Me. function to find the command button name it adds underscores where the spaces were in the button name. I tried changing it to not include the underscores and with [] around the button name (with and without spaces) but it is still visible.

Anyone know why I can't make it invisible? I don't want to change the button names for fear it will hose up something else in this ancient, but highly utilized, system.
 
Hi!

Have you checked to make sure the recordset is returning the correct id?

Just put in a Msgbox rs!cdmid to be sure.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Just an idea to help pinpoint where the problem is. How about creating another button that has spaces in the name and is only visible to you. If that works, try hiding it at a different point in the code. If that works, there must be something in the code that's preventing or over-ridding the attempts to hide the old button.
Hope that helps.
 
Yes I'm getting a valid return from the recordset, my appologies. I should have mentioned that in my previous post.

I actually have other command buttons on the form that I'm hiding (depending on who logs in) using the same recordset. They're command buttons I created that use vba instead of macros though.

Sorry for the confusion.
 
Hmm!

Does the form run any code or macros on load, opening or activating? If so, maybe that has something to do with it. The only other thing I can think of is to make sure that you actually have the correct name for the button. But since you used the . operator, Access should have been showing you the names as you typed so that doesn't seem to be an option. One other thing to try, leave out the If statement and see if the button goes invisible.



Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Have you tried this ?
Me.Controls("open main cra form from switchboard").Visible = False

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I have decieded to replace the existing button with a new one and hope it doesn't cause any issues. I know I can hide a new button and I can't think of any scenario where a command button would be called elsewhere in the database.

Thank you all for your suggestions. I appreciate your input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top