Subform Command Button, based on field

npsavidge

Registered User.
Local time
Today, 14:50
Joined
Oct 28, 2009
Messages
15
Hi,

I have a subform, that i wish to have a command button visible on when a control "Activity" is visit, i.e. if me.activity = "Visit" then cmdShowVisitForm.visible =true. This doesnt work.

Is there a way of only showing the command button on the rows that only have a control equal to certain criteria, like below.

Type
Visit BUTTON
Call
Fax
Visit BUTTON


thanks in advance.
 
Hi,

thanks for that. I want this to happen at the subform open stage, and only be visible when the activity textbox in the subform is a visit. Will this do this?
 
yes, it would be something like this:

Code:
if forms!MainFormName.Form.activity = "Visit" then
forms!MainFormName.Form.cmdShowVisitForm.visible = true
end if
 
Hi,

Sorry.

I have put the following in the _Open section on my subform

If Me![Activity] = "Visit" Then
Me!Command21.Visible = True
Else
Me!Command21.Visible = False
End If

It shows the button for all.

The activity type is also in the subform.

DATE
 
sorry, that was meant to say

DATE ACTIVITY TYPE
01/01/09 Email
02/01/09 Visit BUTTON
03/01/09 Phone
 
You should put the code on the On_Current of the main form, not the open event for the subform. Also, not sure which fires first, On Open or On Load. If the value of the text box isn't filled because the record isn't loaded, then the If condition wont be met. Also, if you change records, then the IF statement never gets processed either.

is your subform a continous form?
 
HI,

Sorry about this.

I have my main form frm_Main_View, and my subform sbfActivities. sbfActivities is the control name, not the form name.

In the on current of the main form frm_Main_View, i have done the following

Private Sub Form_Current()
If Forms!Frm_Main_View!sbfActivities.Form!Activity = "Visit" Then
Forms!Frm_Main_View!sbfActivities.Form!Command21.Visible = True
Else
Forms!Frm_Main_View!sbfActivities.Form!Command21.Visible = False
End If
End Sub

It still, doesnt work, any ideas?

Thanks
 
No it won't. This has nothing to do with referencing the subform controls properly. From the description the OP is apparently using a Continuous Form as a subform, and wants a command button to appear or not, on any given record, depending on the value of [activity].

All instances of unbound control, such as a command button, will reflect the same formatting, on Continuous Forms. If the button is visible on one record, it will be visible on all records, and vice versa.

In Contiuous and Datasheet Forms you can use Conditional Formatting to format some controls on a record-by-record basis, but command buttons are not among those that can be controlled in this manner

About the only thing you can do in this kind of situation is to enable/disable the command button depending on the value in [activity] using code in the Form_Current event of the form the subform is based on. The button will still be visible but unusable.
 
Hi,

Thanks for your help. I have had a go at this before, and i think the general answer was that it cant be done. :)

I have done it using a conditional formatted text box, to look like a button, based on a dlookup for the activty on that activity ID, returning a boolean response for its type, TRUE if visit, FALSE if not.

Thanks again.

Nathan.
 

Users who are viewing this thread

Back
Top Bottom