Enable Button

tarcona

Registered User.
Local time
Today, 08:30
Joined
Jun 3, 2008
Messages
165
I searched Google and this forum for the answer, but I didn't find it.
I have a combo box 'cmbDisposition' in a subform 'LeadInformationSubform'.
When the user choses "Won" from the combo box, I want a button 'btnMoreInfo' in the mainform 'AllRecordsSearch' to be enabled. If the combo box has anything else but "Won", I want the button disabled.

I put a button in the subform to see if it would work....just to try it. I tried this code, but it didnt work:

Code:
Private Sub Form_Current()
If (Me.cmbDisposition.Value = "Won") Then
    Me.btnMoreInfo.Enabled = True
Else
    Me.btnMoreInfo.Enabled = False
End If
End Sub

I also tried this when the button is on the main form like I want. But this didnt work:

Code:
Private Sub Form_Current()
If (Me.cmbDisposition.Value = "Won") Then
    Forms!AllRecordsSearch!btnMoreInfo.Enabled = True
Else
    Forms!AllRecordsSearch!btnMoreInfo.Enabled  = False
End If
End Sub
 
does your combo box just have text in it, or is it from a table or query?
 
Hi,

when you reference controls between mainform and subform, the syntax is a bit different ... check out this link so that you will reference it correctly.
 
The combo box just has text within it. The only choices are "Won" and "Lost". If "Won" than enable btnMoreInfo. If "Lost" or blank then btnMoreInfo is disabled.
 
look at the link max gave you. you will find your solution
 
Yes, thanks for the link.

Would I use this?

Me.Parent.Parent!ControlName

I tried that and I dont know what Parent would be....I tried just:

Me.Parent.Parent!btnMoreInfo

But that didnt work...
 
Hi,

If you want to reference a control on a mainform from a subform you should use:

Me.Parent!ControlName
 
Sorry everyone. Today is not my day.

How do you say that you want the button enabled?

I put Me.Parent!btnMoreInfo.Enabled = True

but I doubt that is right....and of course, I tried it and didnt work.
 
where did you put that code because the reference is correct now
 
I placed the code in my subform. Here is the complete code:

Code:
Private Sub Form_Current()
If (Me.cmbDisposition.Value = "Won") Then
    Me.Parent.Parent!btnMoreInfo.Enabled = True
Else
    Me.Parent.Parent!btnMoreInfo.Enabled = False
End If
End Sub

The error reads:

Run-time error '2452'

The expression you entered has an invalid reference to the parent property.
 
Hi,

You're repeating the word parent twice, it should be there only once. Moreover, you have to check how many column count your combo has, because if you have 2 and not 1, then it should read Me.cmbDisposition.Column(1)
 
My column count is 1.
I put this now:

Code:
Private Sub Form_Current()
If (Me.cmbDisposition.Value = "Won") Then
    Me.Parent!btnMoreInfo.Enabled = True
Else
    Me.Parent!btnMoreInfo.Enabled = False
End If
End Sub

The error:

Run-time error '2452'

The expression you entered has an invalid reference to the parent property. I think it is with the .Enabled.
 

Users who are viewing this thread

Back
Top Bottom