Full Version: Hiding a command button until text is entered
UtterAccess Forums > Microsoft® Access > Access Forms
skelly
Hi
I have my database working very nicely thanks to several members of UA (many thanks to you all). However....
In one form, I would like to hide the command button that is used to save the record. This button is currently set so that VISIBLE = YES, when it is clicked it saves the record and opens a different form. What I really would like is that the button is not visible until text is entered into the last textbox on the form.
I am sure that this can be done, however I also know that I can't quiet work out how it can be done?
Any Offers??
Thanks in advance,
Skelly
cheekybuddha
Hi Skelly,
lace the follwing line of code in both the OnCurrent and AfterUpdate events of your form:
CODE
    Me.cmdButtonName.Visible = (Len(Me.txtTextBoxName & vbNullString) > 0)

This expression will check whether your textbox contains either Null or an empty string. If so, it returns False and thus sets the visible property of your command button to false, otherwise it returns True ands sets the command button's visible property accordingly.
If you want the button to appear before you leave the textbox then place the line in the textbox's OnChange event as opposed to its AfterUpdate event.
hth,
d
Rainlover
In the OnOpen event of the form
e.Command.Visible = False
In the after update event of the Text box
me.Command.visible = True
It would also be a good idea to check for null value in the text box before making the command visible
skelly
Guys this is great, I think ???
know how to find the code for the objects on the form using the menu bar, but all that is shown there is the VBA code for general and then the code behind each of the objects.
Which library etc do I need to use to see the whole forms code I.E. the OnOpen or OnCurrent event for the form, not the objects in the form ??
Thanks again.......
Skelly
Rainlover
The EVENTS we are refering to are part of the Properties box. Do you understand what the properties box is?
skelly
Hi Rainlover
Thanks for your patience. Yes I understand what the properties box is, and I have found the lines mentioned and added the line that you provided, however when I go to open the form I get a error message that the macro me can not be found.
I guess that this is me doing something wrong but I can't work out what?
Any ideas?
Thanks again,
Skelly
Rainlover
Don't know.
What is needed here is to find where the error is comming from.
Rem out the code you have written and replace it with.
sgbox "Hello"
This should not create an error. If it does then we need to look further. It is bed time for me will help more tomorrow.
kbrewster
It sounds like you are typing the code right in the property window! You need to select [Event Procedure] from the drop down, and then type the code in the VBA window!
skelly
OK Thanks Des.
OKristen,
I have an [event procedure] available for 'OnLoad' but nothing for 'OnOpen' ? Even when I select the [event procedure] for OnOpen I dont get the code builder option ??
Thanks,
Skelly
kbrewster
You have to select [Event Procedure] and then click the three dots, and then choose Code Builder. Is this what you are doing?
skelly
Hi Kristen,
omething here is not quiet right (it's probably me ! ). I don't even get the three dots ?
I will try to zip the database, (all of the databases that I have that I don't need help with zip at 80% this one a lousey 2%).
Is that OK?
Thanks,
Skelly
kbrewster
You can try emailing it to me, and I will see what is wrong!
skelly
Doh.....
It's working YEY ! !
It was me being stupid, I am almost 49 years old and I don't always understand the syntax of what I am being told, after a few hours away from it I went back and it bacame clear what I was doing wrong.
Highlight the Form, Design View, PROPERTIES not CODE Doh....
MANY, MANY THANKS TO KRISTEN, DES AND CHEEKYBUDDHA.
cheekybuddha
Hey skelly,
I'm glad you got this working! thumbup.gif
Orecommended that you placed the code in the OnCurrent event as opposed to OnOpen or OnLoad because it will fire whenever you navigate to a different record as well (and of course when the form opens too!).
Good luck with your project,
d
skelly
Thanks Mate,
ye for now.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.