Close Button/required Field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KMEscherich
    New Member
    • Jun 2007
    • 69

    #1

    Close Button/required Field

    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
  • hyperpau
    Recognized Expert New Member
    • Jun 2007
    • 184

    #2
    Originally posted by KMEscherich
    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.

    [CODE=vb]Private Sub Command325_Clic k()

    If IsNull(Me.Contr ol1) Then
    MsgBox "Control 1 is required"

    ElseIf IsNull(Me.Contr ol2) Then
    MsgBox "Control 2 is required"

    ElseIf IsNull(Me.Contr ol3) Then
    MsgBox "Control 3 is required"

    ElseIf Isnull(Me.Contr ol4) Then
    MsgBox "Control 4 is required"

    Else
    Me![Name of your Date and Time Control] = Now( )
    DoCmd.Close

    End If

    End Sub[/CODE]


    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.

    Comment

    Working...