Discussion Locked

Access 2000 Focus and Disable

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a form and two subforms which are placed on three tabs, tbctl1 (Page1, main, Page2, sub, Page3, sub which is programmed to be a sub for Page2). Following is the code behind three switchboard commands;

cmd1:
Private Sub cmd1_Click()
DoCmd.OpenForm "frmAddARisk"
With Forms!frmAddARisk
!Page1.Visible = True
!Page2.Visible = False
!Page3.Visible = False
!Page4.Visible = False
!Page5.Visible = False
!Combo140.Enabled = False
!txtRiskLossHoursActual.Enabled = False !txtRiskResolutionDate.Enabled = False
!txtRiskEntryDate.Enabled = True
!txtRiskSubmittedBy.Enabled = True
!txtRiskTitle.Enabled = True
!txtRiskDesc.Enabled = True
!txtRiskLossHoursEst.Enabled = True
End With
End Sub

cmd2:
Private Sub cmd2_Click()
DoCmd.OpenForm "frmAddARisk"
With Forms!frmAddARisk
!Page1.Visible = True
!Page2.Visible = False
!Page3.Visible = False
!Page4.Visible = False
!Page5.Visible = False
!Combo140.Enabled = True
!txtRiskLossHoursActual.Enabled = True
!txtRiskResolutionDate.Enabled = True
!txtRiskEntryDate.Enabled = False
!txtRiskSubmittedBy.Enabled = False
!txtRiskTitle.Enabled = False
!txtRiskDesc.Enabled = False
!txtRiskLossHoursEst.Enabled = False
MsgBox "To Modify A Risk You Must Select A Risk Title"
End With
End Sub

cmd3:
Private Sub cmd3_Click()
DoCmd.OpenForm "frmAddARisk"
With Forms!frmAddARisk
!Page1.Visible = False
!Page2.Visible = True
!Page3.Visible = False
MsgBox "To Add A Risk Cause You Must Select A Risk"
End With
End Sub

I have two issues?
1. When I try the cmd3 button first (which is Page2), I get the error ?You can?t hide a control that has the focus?.
2. I want to disable fields on Page 2 until the combo box (on Page 2) is selected.

I have tried coding this? I hope this is specific enough. Does anyone have code and advice as to where to put it?

5 replies

by seagull data services

It sounds like the cmdbutton in on a tab rather than on a seperate part of the form. When you try to change the tab it hides all controls on the tab and if the button is on the tab then it can't do it because it has the focus.
What you need to do is A. Move the button off the tab onto a blank spot in the detail section or the form header or footer
OR
B. shift the focus from the command button to another control on the form, e.g. put me..setfocus as the first line of the clickevent.
HTH

by seagull data services

I missed the second part of your question first time around
I would suggest that you create a function that uses the controls collection and loop through the controls enabling/disabling each one on page 2 except the combo box. You could use a boolean argument to specify whether the enabled property is to be turned on or off
Set all the controls, except the combo, to disabled by default and when a new record is created (form current event - run the function)
Once an acceptable value has been entered/selected in the combo box you can run the function to enable the controls.

This discussion is closed to new replies.