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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable/Disable Command Button on a SubFrom

Status
Not open for further replies.

Cleis

Technical User
Jun 4, 2000
197
US
Hi Group:
I'm trying to enable/disable a command button called cmdSelect in a subform. I'm getting object doesn't suport this property or method. Any ideas?


If [txtCurrentPeriod] <> [txtPeriodHeader] Then

Me!lblUnlock.Visible = False
Me!lblLocked.Visible = True
Me![subformDetail].Form.AllowEdits = False
Me![subformDetail].Form.AllowDeletions = False
Me![subformDetail]!cmdSelect.Enable = True

End If

If [txtCurrentPeriod] = [txtPeriodHeader] Then

Me!lblLocked.Visible = False
Me!lblUnlock.Visible = True
Me![subformDetail].Form.AllowEdits = True
Me![subformDetail].Form.AllowDeletions = True
Me![subformDetail]!cmdSelect.Enable = False

End If
End Sub

I've also tried different syntax to no avail Forms!frmPostAppliedCash!subformDeail!cmdSelect.Enable = False


I don't understand why this doesn't work??!! I've done this hundreds of time!


Thanks for you time
 
Hi Cleis,
Try the following...

Code:
Dim ctl As Control
Set ctl = forms!nameofmainform.forms!subformDetail

'I have left these out of the if then else statment because _they do not change! according to your coding

ctl!lblUnlock.Visible = False
ctl!lblLocked.Visible = True

If [txtCurrentPeriod] <> [txtPeriodHeader] Then
   ctl.AllowEdits = False
   crl.AllowDeletions = False
   ctl!cmdSelect.Enable = True                                
else
   ctl.AllowEdits = True
   ctl.AllowDeletions = True
   ctl!cmdSelect.Enable = False                     
End If
End Sub


Ian Mayor (UK)
Program Error
Programmers do it one finger at a time!
 
sorry, just reread you code so a change is needed

Code:
Dim ctl As Control
Set ctl = forms!nameofmainform.forms!subformDetail

If [txtCurrentPeriod] <> [txtPeriodHeader] Then
   ctl!lblUnlock.Visible = False
   ctl!lblLocked.Visible = True
   ctl.AllowEdits = False
   crl.AllowDeletions = False
   ctl!cmdSelect.Enable = True                                
else
   ctl!lblUnlock.Visible = True
   ctl!lblLocked.Visible = False
   ctl.AllowEdits = True
   ctl.AllowDeletions = True
   ctl!cmdSelect.Enable = False                     
End If
End Sub

the lblunlock and lbllocked coding had been swoped around in your original code and I hadn't noticed.

Ian Mayor (UK)
Program Error
Programmers do it one finger at a time!
 
As stated by ProgramError, the Form keyword might do the trick when referencing subform controls.

Another thing, is that the subform itself is a control on the main form, and must be referenced by its control name, which can differ from the name as viewed in the database window. See How to refer to a control on a subform or subreport in Access 2000 for more info. Easiest way of obtaining correct reference (in my view), is to invoke the expression builder from somewhere, then doubleclick through forms, loaded forms, main form, subform and a control on the subform ... on the resulting reference, strip off/alter as necessary and ...

Roy-Vidar
 
Hi Program Error!

I tried your suggestion to no avail. I'm still getting the same error message. I know this is something really freakin stupid. Why I can't ref a command button on a subform is totally mind blowing! Either way, I've wasted way too much time on this. I decided on a work around by using error handling instead.

As far as the labels being visible, I reversed their placement in the true and false part of the if statement. They work, I should have been a little more careful when I entered this post.

Thanks!


 
How are ya Cleis . . .

Perhaps:
Code:
[blue]   [subformDetail].Form!cmdSelect.Enabled = [/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top