I have a form with a subform, with three buttons one "close", "save and exit" and "add and Record', the add and record allows me to add more records, what happens is that i cannot disable all of the controls second image, namely the fitting combo box which is in the subform, due to an error that states unable to disable control due that it still has focus,
i have tried to create another control to take the focus but still comes up with an error.
Main form code
Code:
Option Compare Database
Option Explicit
Private Sub cboStation_AfterUpdate()
Me.cboStaff = Null
Me.cboStaff.Enabled = True
Me.cboStaff.Requery
Me.cboStaff.SetFocus
End Sub
Public Sub cboStaff_AfterUpdate()
Me.sbfNew_PPE.Enabled = True
Me.sbfNew_PPE.SetFocus
Me!sbfNew_PPE.Form!txtChipNumber.Enabled = True
Me!sbfNew_PPE.Form!txtChipNumber.SetFocus
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.cboStation.SetFocus
Me.cboStaff.Enabled = False
Me.sbfNew_PPE.Enabled = False
End Sub
Private Sub cmbAddRecord_Click()
On Error GoTo Err_cmbAddRecord_Click
If IsNull(cboStation) Then
MsgBox ("You have to enter data first!")
Me.cboStation.SetFocus
ElseIf IsNull(cboStaff) Then
MsgBox ("You have to enter data first!")
Me.cboStaff.SetFocus
Else
DoCmd.RunCommand acCmdSaveRecord
Me.cboStaff = Null
Me.cboStaff.SetFocus
Me!sbfNew_PPE.Form!txtChipNumber.Enabled = False
Me!sbfNew_PPE.Form!cboGarmentType.Enabled = False
Me!sbfNew_PPE.Form!lblSize.Caption = "Size"
Me!sbfNew_PPE.Form!cboSize.Enabled = False
Me!sbfNew_PPE.Form!cboFitting.Enabled = False
Me.sbfNew_PPE.Enabled = False
End If
Exit_cmbAddRecord_Click:
Exit Sub
Err_cmbAddRecord_Click:
MsgBox Err.Description
Resume Exit_cmbAddRecord_Click
End Sub
Private Sub cmbClose_Click()
Me.Undo
DoCmd.Close acForm, "frmAdd_New_PPE"
End Sub
Public Sub cmdExitAndSave_Click()
On Error GoTo Err_cmdExitAndSave_Click
If IsNull(cboStation) Then
MsgBox ("You have to enter data first!")
Me.cboStation.SetFocus
ElseIf IsNull(cboStaff) Then
MsgBox ("You have to enter data first!")
Me.cboStaff.SetFocus
Else
DoCmd.GoToRecord , , acNewRec
DoCmd.Close acForm, "frmAdd_New_PPE"
End If
Exit_cmdExitAndSave_Click:
Exit Sub
Err_cmdExitAndSave_Click:
MsgBox Err.Description
Resume Exit_cmdExitAndSave_Click
End Sub
Subform code
Code:
Option Compare Database
Option Explicit
Public Sub cboFitting_AfterUpdate()
Forms!frmAdd_New_PPE.cmbClose.SetFocus
End Sub
Private Sub cboGarmentType_AfterUpdate()
Me.cboSize.Enabled = True
If (cboGarmentType.Column(1) = "Coat") Then
Me.lblSize.Caption = "Chest"
Else
Me.lblSize.Caption = "Waist"
End If
Me.cboSize.SetFocus
End Sub
Private Sub cboSize_AfterUpdate()
Me.cboFitting.Enabled = True
Me.cboFitting.SetFocus
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.txtChipNumber.Enabled = False
Me.cboGarmentType.Enabled = False
Me.cboSize.Enabled = False
Me.cboFitting.Enabled = False
End Sub
Private Sub txtChipNumber_AfterUpdate()
Me.cboGarmentType.Enabled = True
Me.cboGarmentType.SetFocus
End Sub
when form open for first time
when a record is add
Peter