Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    ReeceBMP007 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    6

    Disable main close, minimise & maximise buttons on single form with popup setting set to yes

    Hi


    I am relatively new to access and I am trying to disable the main close, minimise & maximise buttons on single form with popup setting set to yes

    the code that i am using works when the form is first loaded, however once the user stats to input data the close button reactivates

    the code and form settings are shown below, any help is very much appreciated

    Code:
    Private Function fAllFilled() As Boolean
    Dim strSubName As String
    Dim strModuleName As String
     
    strSubName = "fAllFilled"
    strModuleName = "Form - " & Me.Name
     
    Dim Ctrl As Control
    Dim intCtrlCount As Integer
    Dim intCtrlFilled As Integer
     
        For Each Ctrl In Me.Controls
            If TypeOf Ctrl Is TextBox Then
                If Ctrl.Tag = "x" Then
                intCtrlCount = intCtrlCount + 1
                    If Len(Ctrl.Value) >= 1 Then
                        intCtrlFilled = intCtrlFilled + 1
                    End If
                End If
            End If
        Next Ctrl
     
    If (intCtrlCount - intCtrlFilled) = 0 Then
     fAllFilled = True
    End If
     
        Exit Function
     
    End Function 
    Private Sub cmdClose_Click()
    OK2Close = True
    If Not fAllFilled Then
                Me.Caster.SetFocus
                Me.cmdClose.Enabled = False
                Exit Sub
            
           End If
           
        On Error GoTo HandleError
        DoCmd.RunCommand acCmdSaveRecord
        DoCmd.Close ObjectType:=acForm, ObjectName:=Me.Name, Save:=acSavePrompt
    HandleExit:
        Exit Sub
    HandleError:
        MsgBox Err.Description
        Resume HandleExit
    End Sub
    Last edited by ReeceBMP007; 11-05-2021 at 11:42 AM.

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Very hard to follow and troubleshoot code like that. Please enclose in code tags (use # on forum posting toolbar) and indent properly. Will do it for you this time so that we can try to make sense of what's going on. If you have code that deals with users entering data, might need to see that too since the posted code doesn't seem to be concerned with that.
    Code:
    Private Function fAllFilled() As Boolean
    Dim strSubName As String
    Dim strModuleName As String
    
    strSubName = "fAllFilled"
    strModuleName = "Form - " & Me.Name
    
    Dim Ctrl As Control
    Dim intCtrlCount As Integer
    Dim intCtrlFilled As Integer
    
    For Each Ctrl In Me.Controls
      If TypeOf Ctrl Is TextBox Then
        If Ctrl.Tag = "x" Then
          intCtrlCount = intCtrlCount + 1
          If Len(Ctrl.Value) >= 1 Then
             intCtrlFilled = intCtrlFilled + 1
          End If
        End If
      End If
    Next Ctrl
    
    If (intCtrlCount - intCtrlFilled) = 0 Then
      fAllFilled = True
    End If
    
    Exit Function
    
    End Function
    
    Private Sub cmdClose_Click()
    
    OK2Close = True
    If Not fAllFilled Then
      Me.Caster.SetFocus
      Me.cmdClose.Enabled = False
      Exit Sub
    End If
    
    On Error GoTo HandleError
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.Close ObjectType:=acForm, ObjectName:=Me.Name, Save:=acSavePrompt
    
    HandleExit:
    Exit Sub
    
    HandleError:
    MsgBox Err.Description
    Resume HandleExit
    
    End Sub
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    ReeceBMP007 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    6
    OK I've edited the post as suggested, for information the data entered on the form is done so by a series of combo boxs

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    have you considered opening the form with borders set to none?

    Alternatively make it a subform to your calling form

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    disable the main close, minimise & maximise buttons on single form with popup setting set to yes
    once the user stats to input data the close button reactivates
    Those are 2 different buttons, yes? A bit confusing the way that's described. The reactivation you refer to must be your command button. Perhaps state how you want things to work rather than what's not working. I say that because IMO it's easier to just prompt when there is missing data rather than compare counts or do math on the controls with/without values.

    What happens if I want to cancel after inputting some of the fields? Am I not stuck because there's no built in close button and no custom one either? A better approach might be to loop, find the ones with tag x that have no data and just present the names of those in a message box - one that allows the user to continue or cancel. In that case the only Close code needed is to close the form. That message box can present all missing field names at once. If your control labels are attached, you can use their captions rather than cryptic control names.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    ReeceBMP007 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    6
    Me.Caster is a combo box & Me.CmdClose is a custom close button. I should say this form opens from a previous machine settings form, once this form is opened the user needs to log the reason for changing the machine settings on the previous form. I want the user to be unable to close the form until all required fields have been populated and only then by my custom close button

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Do other controls such as combos, have x as their Tag property? If not, then there's no need to test the control type. If yes, then can you differentiate between those that are required for this exercise (e.g. use x for some and y for others)? I could put together something that will message all controls at once that are missing data. However, you did not answer the question regarding control labels so cannot do so until then.
    OK, after reviewing I see that it wasn't a question so much as a suggestion based on an "if".
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Setting the controlbox property to no will remove the Max,min, and X.

    I use this procedure to validate controls:

    Code:
    Public Function ValidateForm(frm As Form, TagCharacter As String) As Boolean
    'validated controls must have a label. Ok to use a hidden label if needed.
    
    
        Dim ctl As control
        Dim flg As Boolean
        Dim strOut As String
    
    
        flg = True
    
    
        For Each ctl In frm.Controls
    
    
            If ctl.Tag = TagCharacter Then
                If Nz(ctl.value, "") = "" Then
                    flg = False
                    ctl.BorderColor = vbRed
                    strOut = strOut & Space(10) & "* " & ctl.Controls.Item(0).Caption & vbNewLine
                Else
                    ctl.BorderColor = vbBlack
                End If
    
    
            End If
        Next
    
    
        If flg = False Then
            MsgBox "The following field(s) must be completed:" & vbNewLine & strOut
        End If
    
    
        ValidateForm = flg
    
    
    End Function
    It returns True/False so use that with your close button

    Code:
    if ValidateForm(me,"V8") = true then
    docmd.close acform, Me.Name
    end if
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  9. #9
    ReeceBMP007 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    6
    Thanks Micron for the help, controls are as follows in order: Caster (combobox), RFC Number (combobox), Belt number (Textbox), Problem Observed (Combobox), Setting Changed (Combobox), Tank A (Textbox), Tank B (Textbox), Tank C (Textbox), Effect of Change (Combobox), Change Made By (Combobox), Shift (Combobox) all are required fields except effect of change. Their is also a button to save record with embedded macro and a custom close button. Again thanks for the help

  10. #10
    ReeceBMP007 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    6
    Moke 123 thanks for the help, but I want to disable the Main Acess close minimise & maximize buttons, this is also a has popular settings set to yes so I'm not to sure that would work setting the control property to no, I could be wrong though as I am no expert

  11. #11
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    OK, but that doesn't answer my question as to whether or not the tag property value is the same for all of them. As noted, if you set the Control Box property to No in the property sheet, there won't be any min/max or close button on the form unless you provide a command button for that. Your code has nothing that sets this property so I don't understand your comment about that part. Moke123 has shown a way to pass the form to a function, which I have also done. Since my last post I just threw the following together but it is not meant to be used for any form, just the one that the code is on. Also, you still have not commented on whether or not the labels are attached, so either example will error if one of the controls being checked either has no label or it's not attached.

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim ctl As Control
    Dim strMsg As String
    Dim result As Integer
    
    For Each ctl In Me.Controls
       If ctl.Tag = "x" Then
          If Len(Nz(ctl, "")) = 0 Then
             strMsg = strMsg & "- " & ctl.Controls(0).Caption & vbCrLf
          End If
       End If
    Next
    
    If strMsg <> "" Then
       strMsg = "Cannot save record with these missing values:" & vbCrLf & strMsg
       strMsg = strMsg & vbCrLf & "Click OK to complete record or Cancel to undo."
       result = MsgBox(strMsg, vbOKCancel)
       If result = 0 Then
          Cancel = True
       Else
          Me.Undo
       End If
    End If
    
    End Sub
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    ReeceBMP007 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    6
    Sorry I missed that out yes all tag properties are the same, not sure about the labels being attached but I will check when I'm back at work and let you know thanks for the help

  13. #13
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Quote Originally Posted by ReeceBMP007 View Post
    Moke 123 thanks for the help, but I want to disable the Main Acess close minimise & maximize buttons, this is also a has popular settings set to yes so I'm not to sure that would work setting the control property to no, I could be wrong though as I am no expert
    Pop-up with ControlBox property set to No

    Click image for larger version. 

Name:	cbn.jpg 
Views:	12 
Size:	28.2 KB 
ID:	46554

    In the form properties

    Click image for larger version. 

Name:	cbox.jpg 
Views:	14 
Size:	26.2 KB 
ID:	46556
    Attached Thumbnails Attached Thumbnails cbox.jpg  
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  14. #14
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    yes all tag properties are the same,
    Then I suspect you don't need to worry about what type of control it is. AFAIK, all controls have the tag property, although I'm pretty sure it was not always so. If labels are not attached then for you and anyone else who comes along, you'll either have to
    - attach them, otherwise trying to get Controls(0).Caption will raise an error, or
    - you would have to settle for using the name of the control. If that is like txtCustomer, that is what the user will be prompted to enter a value into. Or
    - you could get the name of the field, but you'd have to bring a recordset into the mix, or
    - you could DLookup a meaningful name from a table of captions for controls.

    Perhaps obvious that the simplest is to have the labels attached. If you have any event code for them, then perhaps you cannot.
    There might be other ways, but that's all I've got for now. Have a good weekend!
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    As noted in my code, you can use a hidden label (visible = no) for the control. The label caption is your best bet as it should be the most descriptive of the field.

    If for some reason you are using the tag property for other purposes you can also use:
    Code:
    If  instr(1,ctl.Tag,TagCharacter) Then
    This would allow you to use the tag property in different procedures.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Popup form causes main form to close
    By GraeagleBill in forum Forms
    Replies: 11
    Last Post: 10-05-2018, 05:40 PM
  2. Replies: 2
    Last Post: 01-19-2017, 02:04 PM
  3. Minimise (not hide) the main ribbon
    By Ruegen in forum Programming
    Replies: 2
    Last Post: 05-18-2014, 10:13 PM
  4. Replies: 4
    Last Post: 01-20-2013, 06:34 PM
  5. Disable master form close button
    By Carpy01 in forum Forms
    Replies: 3
    Last Post: 12-31-2010, 05:41 PM

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