473,321 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Disabling Close Button Temporarily

Ok, another question. This is my first effort at building a database for an organisation so I am trying not to use quick and dirty methods to get around issues. What I want to do (and probably can't) is to disable a data entry form close button (the easy part) so users can't exit the form without finishing it but I also want to enable it at the start of a new entry so a user can close the form before they enter any new data (the hard part). Is there a propert like scrollbars that can be turned on and off via VBA to do this? or is Close Button a one time ting in design view. an example of what I want is this. I normally disable scrollbars as I keep my forms page size but occasionally I enable them in Edit view so users can scroll through the records. I use Me!Form.ScrollBars = 2 to temporarily bypass the property sheet setting. Can I do this with the CloseButton? Thanks
Oct 13 '16 #1

✓ answered by PhilOfWalton

Slightly different approach:

On the Unload I do a check that all neccesary field have been filled in, and if not, cancel the event.

Something like

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2.  
  3.     If IsNull(Hrs) Or IsNull(Date1) Then
  4.         Cancel = True
  5.     End If
  6.  
  7. End Sub
  8.  
Phil

4 3060
ADezii
8,834 Expert 8TB
  1. There is a Form's CloseButton Property but to the best of my knowledge it is Read/Write in Design Mode only. There is, however, a convoluted workaround if you are interested in dynamically setting this Property.
    1. Open the Form in Design/Hidden Mode.
    2. Set the CloseButton Property of the Form to True/False.
    3. Re-open the Form in Normal Mode.
  2. To dynamically disable the Close Button on the Employee List Form:
    Expand|Select|Wrap|Line Numbers
    1. With DoCmd
    2.   .OpenForm "Employee List", acDesign, , , acFormEdit, acHidden
    3.     Forms("Employee List").CloseButton = False
    4.   .OpenForm "Employee List", acNormal, , , acFormEdit, acWindowNormal
    5. End With
  3. If you wanted to actually utilize this approach, this would not be the way to do it. You would create a Public Function that accepts two Arguments (a Form Reference and a Boolean Value). This Function returns a Value indicating Success/Failure. An example would be:
    a Form Reference and a Boolean Value.
    Expand|Select|Wrap|Line Numbers
    1. Public Function fEnableDisableClose(strForm As String, blnState As Boolean) As Boolean
    2. On Error GoTo Err_fEnableDisableClose
    3.  
    4. With DoCmd
    5.   .OpenForm strForm, acDesign, , , acFormEdit, acHidden
    6.     Forms(strForm).CloseButton = blnState
    7.   .OpenForm strForm, acNormal, , , acFormEdit, acWindowNormal
    8. End With
    9.  
    10. fEnableDisableClose = True
    11.  
    12. Exit_fEnableDisableClose:
    13.   Exit Function
    14.  
    15. Err_fEnableDisableClose:
    16.   fEnableDisableClose = False
    17.     MsgBox Err.Description, vbExclamation, "Error in fEnableDisableClose()"
    18.       Resume Exit_fEnableDisableClose
    19. End Function
  4. Sample Function Call:
    Expand|Select|Wrap|Line Numbers
    1. Dim blnRetVal As Boolean
    2.  
    3. blnRetVal = fEnableDisableClose("Employee List", True)
    4.  
    5. MsgBox IIf(blnRetVal, "Success", "FAILURE")
    6.  
P.S. - This is not an Optimal solution, I only propose it since it is a solution.
Oct 13 '16 #2
PhilOfWalton
1,430 Expert 1GB
Slightly different approach:

On the Unload I do a check that all neccesary field have been filled in, and if not, cancel the event.

Something like

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2.  
  3.     If IsNull(Hrs) Or IsNull(Date1) Then
  4.         Cancel = True
  5.     End If
  6.  
  7. End Sub
  8.  
Phil
Oct 13 '16 #3
ADezii
8,834 Expert 8TB
Unless you want to specifically Disable/Enable the Close Button, Phil's approach is much better.
Oct 13 '16 #4
Thanks ADezii and Phil. I was thinking along the lines Phil mentions as a possible but wasn't sure of the syntax. What I have done is set up an unbound control on the form already after the last editable control but before the four checkboxes. It is set to 0 width so it can't be seen. When a user tabs out of the last editable control it checks all controls to make sure they are filled in then passes control to the checkboxes or returns user to the blank control. To ensure that it will continue to do this till all controls are entered it sets a value of 1 in the control only if all required entries are complete. I can use this along the lines of

If IsNull(FrmCh)Then
Cancel = True
MsgBox "You have not completed the form" & Chr(13) & Chr(10) & "Please complete all required fields",vbCritical
End If

Again, Many thanks
Oct 13 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: moose | last post by:
OK Popup window? No problem PDF in popup? No problem But what about a couple of Close Window buttons? Imagine a "Close Window" button at the top of the popup page. Then the PDF which can...
5
by: Reggie | last post by:
Hi and TIA! I have a form and have set the Close Button to false so that users must exit using my close button. However when I open a Report from this form I want the close button to be available...
3
by: Paul | last post by:
Hi I am trying to create an "Update" button for my form. So far I have got it working fine, posting back and updating the record. Great! However, I now want to make it so that when a user...
7
by: Marco Castro | last post by:
How can I disable and then re-enable the close button on a form? Thanks.
13
by: lightzizo | last post by:
All, How can I disable or remove the close button in the screen. thanks
9
by: cor-travel | last post by:
Hi Folk Is there a way to disable the close button for an application? Thank you - Nicolaas
2
by: Bruce | last post by:
Hello, I have a form in an Access 2003 application which opens maximized. Its CloseButton property is set to false. On this form I have a command button that opens a report in preview mode. ...
0
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
5
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
3
by: priyamtheone | last post by:
Hi, I am trying to work on an application that disables the close button (X) on the upper right hand corner of a window. In order to do that I need to use calls to API methods like GetSystemMenu,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.