473,791 Members | 3,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Close Button/required Field

69 New Member
Using Access '97

Hi there, am wondering if there is a way to have a CLOSE button on the form and have it NOT CLOSE the form unless all the REQUIRED controls have an entry.

I have 3 items I would LOVE to find out about:
1 / I have created a button that I have attached to following code to and it seems to check the fields and it gives me a WARNING that a particular field needs to have an entry if something is missing. This is good, and it works.
2 / After it checks, I need to know if there is a way to attach the CLOSE button code to this and have it NOT CLOSE if there is something missing abd CLOSE if all fields have an entry.
3 / If all controls have an entry in them, I need to capture a date and time. If all the fields don't have an entry, I don't want the form to close and also no date.
4 / I also need to capture a 2nd date when all the NOT REQUIRED fields have been entered at a later date.

Is this possible?

Thank you in ADVANCE FOR YOUR ASSISTANCE.
Kind regards



Private Sub Command325_Clic k()


Dim FLAG As Integer

If Not IsNull(Me.F_ERG ONOMICS!ERGO_CO DE) Then
FLAG = 1
End If

If Not IsNull(Me.F_HUM AN_FACTOR!HUMAN _FAC_CODE) Then
FLAG = 1
End If

If Not IsNull(Me.F_PER SONAL!PROT_EQUI P_CODE) Then
FLAG = 1
End If

If Not IsNull(Me.F_POL ICY!POLICY_PROC _CODE) Then
FLAG = 1
End If

If Not IsNull(Me.F_MGM T_SYSTEMS!MGMT_ SYS_CODE) Then
FLAG = 1
End If

If Not IsNull(Me.F_TOO LS!TOOLS_CODE) Then
FLAG = 1
End If

If Not IsNull(Me.F_WOR KPLACE!WORKPLAC E_CODE) Then
FLAG = 1
End If

If FLAG >= 1 Then
FLAG = 0
Else
MsgBox "You need to make an entry in at least one of the KEY FACTORS"
End If



If Nz(Me.SRI) = "" Then
MsgBox ("Missing SRI on the 1st tab.")
End If
If Nz(Me.LOC_CODE) = "" Then
MsgBox ("Missing LOCATION CODE on 1st tab.")
End If
If Nz(Me.COST_CTR) = "" Then
MsgBox ("Missing COST CENTER on 1st tab.")
End If
If Nz(Me.INCIDENT_ DATE) = "" Then
MsgBox ("Missing DATE OF INCIDENT on 1st tab.")
End If
If Nz(Me.INCIDENT_ TIME) = "" Then
MsgBox "Missing TIME OF INCIDENT on 1st tab"
End If
If Nz(Me.WEEKDAY_C ODE) = "" Then
MsgBox ("Missing WEEKDAY INCIDENT OCCURRED on 1st tab.")
End If


End Sub
Jul 10 '07 #1
1 1861
hyperpau
184 Recognized Expert New Member
Using Access '97

Hi there, am wondering if there is a way to have a CLOSE button on the form and have it NOT CLOSE the form unless all the REQUIRED controls have an entry.

I have 3 items I would LOVE to find out about:
1 / I have created a button that I have attached to following code to and it seems to check the fields and it gives me a WARNING that a particular field needs to have an entry if something is missing. This is good, and it works.
2 / After it checks, I need to know if there is a way to attach the CLOSE button code to this and have it NOT CLOSE if there is something missing abd CLOSE if all fields have an entry.
3 / If all controls have an entry in them, I need to capture a date and time. If all the fields don't have an entry, I don't want the form to close and also no date.
4 / I also need to capture a 2nd date when all the NOT REQUIRED fields have been entered at a later date.

Is this possible?

Thank you in ADVANCE FOR YOUR ASSISTANCE.
Kind regards



Private Sub Command325_Clic k()


Dim FLAG As Integer

If Not IsNull(Me.F_ERG ONOMICS!ERGO_CO DE) Then
FLAG = 1
End If

If Not IsNull(Me.F_HUM AN_FACTOR!HUMAN _FAC_CODE) Then
FLAG = 1
End If

If Not IsNull(Me.F_PER SONAL!PROT_EQUI P_CODE) Then
FLAG = 1
End If

If Not IsNull(Me.F_POL ICY!POLICY_PROC _CODE) Then
FLAG = 1
End If

If Not IsNull(Me.F_MGM T_SYSTEMS!MGMT_ SYS_CODE) Then
FLAG = 1
End If

If Not IsNull(Me.F_TOO LS!TOOLS_CODE) Then
FLAG = 1
End If

If Not IsNull(Me.F_WOR KPLACE!WORKPLAC E_CODE) Then
FLAG = 1
End If

If FLAG >= 1 Then
FLAG = 0
Else
MsgBox "You need to make an entry in at least one of the KEY FACTORS"
End If



If Nz(Me.SRI) = "" Then
MsgBox ("Missing SRI on the 1st tab.")
End If
If Nz(Me.LOC_CODE) = "" Then
MsgBox ("Missing LOCATION CODE on 1st tab.")
End If
If Nz(Me.COST_CTR) = "" Then
MsgBox ("Missing COST CENTER on 1st tab.")
End If
If Nz(Me.INCIDENT_ DATE) = "" Then
MsgBox ("Missing DATE OF INCIDENT on 1st tab.")
End If
If Nz(Me.INCIDENT_ TIME) = "" Then
MsgBox "Missing TIME OF INCIDENT on 1st tab"
End If
If Nz(Me.WEEKDAY_C ODE) = "" Then
MsgBox ("Missing WEEKDAY INCIDENT OCCURRED on 1st tab.")
End If


End Sub
This sounds simple. I just don't understand your FLAGS and why I see Nz in your codes.

Let's say, you have 4 required controls.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command325_Click()
  2.  
  3. If IsNull(Me.Control1) Then
  4.     MsgBox "Control 1 is required"
  5.  
  6. ElseIf   IsNull(Me.Control2) Then
  7.     MsgBox "Control 2 is required"
  8.  
  9. ElseIf   IsNull(Me.Control3) Then
  10.     MsgBox "Control 3 is required"
  11.  
  12. ElseIf  Isnull(Me.Control4)  Then 
  13.     MsgBox "Control 4 is required"
  14.  
  15. Else
  16.       Me![Name of your Date and Time Control] = Now( )
  17.       DoCmd.Close
  18.  
  19. End If
  20.  
  21. End Sub

The Only problem I see in your code is that you separated all your
It..Then statements in to several If...Then Statements instead of putting
Then together in just one If...Then...Els eIf...Then...El se Statement.
Jul 12 '07 #2

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

Similar topics

6
2744
by: marcelf3 | last post by:
Hello.. This page opens a window with some information, but everytime the user changes a field in the parent window, the child window needs to be closed. These 2 functions were supposed to do the work. Nota() - opens new window. fechaNota() - closes the window opened by Nota() here is the code.
6
3788
by: Kenny G | last post by:
Reference the below sub: I can't get the message box to close and therefore the user can't enter anything - Y or N in the OralAntibiotics box. Your help is appreciated. Private Sub OralAntibiotics_Enter() If Me.TypeofSurgery <> "Colon Surgery" Then DoCmd.GoToControl "AntibioticAllergy" Else MsgBox "Data Entry Is Required - Enter a Y or an N!", vbCritical, UHS
1
1844
by: Ebrahim | last post by:
This message is in reply to a prev 1 . My application refues to close . Some one had suggested that I might have threads running.. but i solved that problem too . The app still refuses to close . !! Here is the code for one of them !! I call a stop function to disconnect all objects (close ) . I also make a call to Stop in the Dispose() function .
0
5752
by: Oz | last post by:
Hi Using VS.NET 2003, Windows XP SP1, We have a page which has been developed using ASP.NET. On it, is a button which when clicked is supposed to add some data to a table. When the button is selected, it causes the ServerClick event to be called twice. Here's the code: You'll see that there are two grids on the page, and that the function SetupDataGrid populates data to the two grid. There are also
2
1626
by: Bert Szoghy | last post by:
Hello, I am missing something about Visual Basic .NET module variables and window close events. In the following code, after opening Form2 by clicking a button on Form1 and then closing Form2, I would expect to click on the second Form1 button and get intMyValue = 0. Form2 has code to reinitialize it in its close event, but this doesn't seem
1
4474
by: Stephen D Cook | last post by:
What I am trying to do is have a set of option buttons which are required to click one. If the person doesn't click any before insert, they get an error. If they do click one, it inserts into the field in the table and then clears the form for the next entry. I have a form tied to a table. In the table is a lookup field. In the form I have a frame with 5 option buttons in it. Outside the frame I have a text box. I bound the text box to...
1
4508
by: Stephen D Cook | last post by:
In my form I have an option group with 3 option buttons. My form is tied to a table. the options are Temp, Permanent and Overtime. I have these inside a frame. I have an AddRecord button to enter the data into the table. After the record is Added the option buttons are emptied. I want to require the person to click one of the option buttons, which enters the type of employee it is. In the click event of the AddRecord button I have the...
7
4986
by: tarun.kataria | last post by:
Hi All, Is there any way to detect that the user is trying to Xout the browser window instead of hitting a button. Because in my application I want to make it sure that they dont do it either knowingly or accidently. Its an ASP.NET application with C#. Thanks Tarun
2
4329
by: Del | last post by:
I have a popup form that consist of a single field called EnteredBy and a Subform that has three fields. The popup form also has a button in the Form Footer called close. In the On Click event I have the following code. DoCmd.Close I want the EnteredBy field to be a required field. So in the On Exit event for that field I have the following code.
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10156
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9997
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.