Hide form button if field is "No" (1 Viewer)

BadBoy House

Registered User.
Local time
Today, 17:48
Joined
Oct 8, 2009
Messages
54
I have a button on a form which is configured to display a separate form to view budget details when it is clicked on:



This works well however I only want the button to be visible if there is a 'Yes' in the 'Has Budget?' field on the form.

The name of the button is ViewBudget and the control source for the 'Has Budget' field is as follows:

=IIf([BudgetID]>0,"Yes","No")


Is there any way to achieve this? I think the form would look much better if the button only appeared next to records that the button can be used for.

Thanks in advance
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:48
Joined
May 21, 2018
Messages
8,463
I am assuming you do not want all the buttons to hide or show depending on what record is selected. So the answer is no unless my assumption is wrong. You could have a single button in header or footer. The only way to fake it that I can think of is to make the command buttons into textboxes and fake them to look like command buttons. Use conditional formatting to enable and disable the textboxes.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:48
Joined
May 21, 2018
Messages
8,463
Not the same thing. That is code for a single form view. In a continous form there is really only one command button the rest are painted. If you show or hide one it will show or hide all. If that is fine (which is not normally what people want) then you can write code in the on current event. But if you want to show the buttons and have certain enabled and disabled then you must fake it with a text box and conditional formatting.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:48
Joined
Oct 29, 2018
Messages
21,358
What would the way be to achieve this with text boxes so that it opens the appropriate form when clicked on?
Hi. You could use the same code you have now for the button in the Click event of your Textbox.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:48
Joined
May 21, 2018
Messages
8,463
What would the way be to achieve this with text boxes so that it opens the appropriate form when clicked on?
I did not notice you changed the question. Is the issue about conditionally hiding command buttons, or is there a question about opening a form?
 

BadBoy House

Registered User.
Local time
Today, 17:48
Joined
Oct 8, 2009
Messages
54
Basically the View Budget button currently shows for each record. If you click on the button for a row where the 'Has Budget' column shows a 'Yes' it takes you to the budget form for that record.

If you click on the button for a record where there is a 'No' in the 'Has Budget' column it takes you to the blank/new record page on the budget form.

I would like to hide the View Budget button where there is a 'No' in the 'Has Budget' column.

It doesn't have to be a button - if there is a way of doing this with a text link or something similar instead that would be ok.

Thanks
 

Minty

AWF VIP
Local time
Today, 17:48
Joined
Jul 26, 2013
Messages
10,355
Use conditional formatting to make the yes no field look like a hyperlink when its value is yes.

Open the budget form on double click of the yes , if it's no don't open the form.
 

BadBoy House

Registered User.
Local time
Today, 17:48
Joined
Oct 8, 2009
Messages
54
Thanks Minty - I think I follow.

On a double click of the Yes box when it opens the budget form, how do I get it so that it opens the budget form containing the budget details specific to that job?
 

Minty

AWF VIP
Local time
Today, 17:48
Joined
Jul 26, 2013
Messages
10,355
The current JobID will be available to you when that control is double clicked.

So you would code it something like (air code - untested, you'll need to change field names / controls to match your forms and tables)


Code:
Dim sArgs as String

sArgs = Me.JobID

DoCmd.OpenForm "frmYourOtherForm", acNormal, , , , , sArgs

Then in your other form use the Me.openArgs property to go to the correct record.

The other route is to use a where condition on opening the form to open it with just that record ;

Code:
DoCmd.OpenForm "frmYourOtherForm", acNormal, , "[JobID] = " &  Me.JobID

Depends on your preference.
 

BadBoy House

Registered User.
Local time
Today, 17:48
Joined
Oct 8, 2009
Messages
54
Thanks Minty - I went with your second option above. Works perfectly.
 

Users who are viewing this thread

Top Bottom