Results 1 to 3 of 3
  1. #1
    jaymin is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Jan 2012
    Location
    gold coast Australia
    Posts
    57

    disable controls on a subform,

    I have a form, it has two combo boxes and a subform with four controls one txt and three combos, When the form opens the first combo is active and the second combo is enabled to false, so is the subform and the controls on it "see first image", as i add data into the control the other update event activates and the next control becomes active. the subform becomes active and so on for each control on it. when the last control is used its focus is directed to one of three buttons. close, exit and save and add record.
    the form controls which are set to enabled to false work just how i would like, but when i press the add record button, i get "you can't disable a control while it has focus". .
    or if i do not put the focus on the close button it works but not all the controls on the subform get set to enabled to false "see second image".
    Click image for larger version. 

Name:	new form.jpg 
Views:	19 
Size:	21.5 KB 
ID:	8156
    Click image for larger version. 

Name:	Add_Record.jpg 
Views:	19 
Size:	23.0 KB 
ID:	8157

    Form Code

    Option Compare Database

    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.Form.txtChipNumber.Enabled = True
    Me.sbfNew_PPE.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
    Err_cmbAddRecord_Click:

    If IsNull(cboStation) Then
    MsgBox ("You have to enter data first!")
    Me.cboStation.SetFocus
    Cancel = True

    ElseIf IsNull(cboStaff) Then
    MsgBox ("You have to enter data first!")
    Me.cboStaff.SetFocus
    Cancel = True

    Else
    DoCmd.RunCommand acCmdSaveRecord
    Me.cboStaff = Null
    Me.cboStaff.SetFocus
    Me!sbfNew_PPE.Form!cboGarmentType.Enabled = False
    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
    Err_cmbAddRecord_Click:

    If IsNull(cboStation) Then
    MsgBox ("You have to enter data first!")
    Me.cboStation.SetFocus
    Cancel = True

    ElseIf IsNull(cboStaff) Then
    MsgBox ("You have to enter data first!")
    Me.cboStaff.SetFocus
    Cancel = True

    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

    Option Compare Database
    Public Sub cboFitting_AfterUpdate()
    Me.Parent!txtblank.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.SetFocus
    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


    Hope someone is brave enough to help me
    Peter

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I'm surprised your code runs at all. Did you try compiling it? The label Err_cmbAddRecord_Click is defined twice in the procedure cmbAddRecord_Click - you will get a compilation error.

    Fix that error and see how it works. I cannot see any other obvious error.

    ALWAYS compile you code after you make any changes to it, and you should always put Option Explicit in every module, after Option Compare Database. You'd be surprised how many typos that catches.

    John

  3. #3
    jaymin is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Jan 2012
    Location
    gold coast Australia
    Posts
    57
    John_G,
    The label Err_cmbAddRecord_Click, in my working copy has not been doubled up, the suggestion about compiling the code and the "option explicit" has found some faults with the code, thank you very much for your time and effort in helping me.
    Peter

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to add controls on subform
    By rashima in forum Forms
    Replies: 1
    Last Post: 04-01-2012, 06:16 AM
  2. subform controls
    By donnan33 in forum Forms
    Replies: 30
    Last Post: 02-27-2012, 09:06 AM
  3. Disable new entry in subform
    By mdewell in forum Forms
    Replies: 3
    Last Post: 01-05-2012, 02:38 PM
  4. Replies: 1
    Last Post: 08-06-2010, 07:50 PM
  5. subform controls hidden
    By bkelly in forum Forms
    Replies: 0
    Last Post: 09-26-2009, 10:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums