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!

Displaying a button conditionally 1

Status
Not open for further replies.

matpj

Technical User
Mar 28, 2001
687
GB
Hi,

I have a button that displays a form - but I only want it visible and active when the contents of a list box is set to a certain choice!

is this poissible, and how?
Also,

is it possible to have certain fields on the form automatically filled in with the contents of the corresponding fields from the form that holds the button above?
 
In the After Update event for the listbox, put the following code:
[tt]
If (Me![ListBoxName]= YourValue) Then
Me![ButtonName].Visible = True
Else
Me![ButtonName].Visible = True
End If
[/tt]
In the On Click even for the button, put the following code:
[tt]
Dim stFormName as String
//Open the form
stFormName = "FormName"
DoCmd.OpenForm stDocName

//Fill the fields
Forms![FormName]![Field1] = Me![FieldA]
Forms![FormName]![Field2] = Me![FieldB]
...

[/tt]

Hope that helps

Jonathan
________________________________________
It is not fair to ask of others what you are unwilling to do yourself.
-Eleanor Roosevelt
 
Someone's got their C++ head on.....

matpj - Try using ' instead of // for comments
 
Yes, I'm working in C++ in the other window. Sorry about the confusion! Jonathan
________________________________________
It is not fair to ask of others what you are unwilling to do yourself.
-Eleanor Roosevelt
 
I think the Else statement should read
Me![ButtonName].Visible = False
could be wrong though
HTH - Michael
 
Yeah, I noticed the Else statement thing. I didn't comment my code anyway (naughty me!)

I did notice something though.
As soon as I load up the form, the button is visible. When I then change the feild to something other than the condition I want, the button disappears, and then the code works!

how do I get the button to start off invisible?
 
Try changing the visible property of the button in form design view to Visible = No.

HTH
 
Sloppy code! I can't believe I wrote such sloppy code!

Jonathan
________________________________________
It is not fair to ask of others what you are unwilling to do yourself.
-Eleanor Roosevelt
 
Thanks again!
one more query.

It is not visible until the user selects 'Late Order' from the list. then the button appears. The only thing is. If you navigate backwards or forwards, the button is now visible all the time.
I need the form to ONLY show the button when the contents of the 'Problem Type' combo-box is set to 'Late Order' - even on past records!

how can this be achieved?
 
In the On Current event of the form, put in code (if.. statements from above) that evaluates your listbox and sets the .Visible property.

The On Current event is called when you open your form or move to a new/different record. Jonathan
________________________________________
It is not fair to ask of others what you are unwilling to do yourself.
-Eleanor Roosevelt
 
use the 'OnCurrent' event of the form to

me.cmdButton.visible = False

Hang in there....!






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top