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

    Disabling form controls

    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
    Click image for larger version. 

Name:	new form.jpg 
Views:	16 
Size:	21.5 KB 
ID:	8283


    when a record is add
    Click image for larger version. 

Name:	Add_Record.jpg 
Views:	16 
Size:	23.0 KB 
ID:	8282



    Peter

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    • In the upper, left-hand corner of your Form, create a Textbox
    • Name it FauxControl
    • With it in the upper, left-handmost corner, re-size it until it is basically just a dot
    • As the last line in the TargetControl code, use this

    Me.FauxControl.SetFocus

    Then use this code
    Code:
    Private Sub FauxControl_GotFocus()
     TargetControl.Enable = False
    End Sub

    You cannot set Focus on a Control, FauxControl in this case, that is invisible, so you merely shrink it to a size that is 'invisible' to the human eye. Then you use its code to Disable the TargetControl.

    Remember to replace TargetControl with the actual name of the Control you want to Disable.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

    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
    i have tried this before but it causes the focus error on this line instead "Me.sbfNew_PPE.SetFocus", is this the correct syntax for this .
    Peter

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

Similar Threads

  1. Using Tab controls within a form
    By crowegreg in forum Forms
    Replies: 2
    Last Post: 08-25-2011, 08:17 PM
  2. Controls within form
    By crowegreg in forum Forms
    Replies: 4
    Last Post: 05-31-2011, 08:39 AM
  3. Replies: 7
    Last Post: 02-08-2011, 10:59 AM
  4. Disabling textbox on reloading the form
    By accesscoder in forum Forms
    Replies: 3
    Last Post: 10-16-2010, 05:55 PM
  5. Replies: 0
    Last Post: 10-12-2009, 08:26 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