Results 1 to 14 of 14
  1. #1
    Join Date
    Aug 2013
    Posts
    82

    Unanswered: Required Fields After Finished Date

    Is there a way to ensure certain fields are not left blank after the finished date field is entered on a form?

    I don't want these to be required until the finished date is entered.

    Thanks for the help.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you can do whatever you like in terms of validation
    place some code in the forms before update event
    validate what you need to, if there is an error set cancel = true to halt saving of the record
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Aug 2013
    Posts
    82
    Okay I will try. I am still learning code however.

    Could you be a little more specific?

  4. #4
    Join Date
    Aug 2013
    Posts
    82
    I have this code but it still allows the user to print reports without the required field being entered:

    I put this in my form's Before Update event:

    If IsNull(FIELD1) = False And FIELD1 <> "" Then
    If IsNull(FIELD2) = True Or FIELD2 = "" Then

    FIELD2.SetFocus
    FIELD2.BackColor = vbYellow

    MsgBox "You must enter a value in Field2", vbCritical
    Exit Sub

    Else

    FIELD2.SetFocus
    FIELD2.BackColor = vbWhite

    End If
    End If

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    at what point did you set cancel = true is there is a validation error?
    if you don't set the cancel flag = true then when exiting the before update event Access will save the record.
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Aug 2013
    Posts
    82

    Required Fields After Finished Date

    What I actually want is to set this validation rule before the print buttons on the form for reports is allowed.

    After Finished Date is entered I want these fields to be required before printing reports:

    Technician
    Repairman
    Test Equipment
    Disposition
    Attached Thumbnails Attached Thumbnails AFR FORM1.png  

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so reading between the lines a user cannot print the report unless all the relevant data is completed

    there re two styles of validation. per control and per form. in both cases you put code in the entities before update event. per control means that when you leave the control the before update event is fired, however it only fires when you leave that control, if you don't put anything in the control then the event doesn't fire
    the per form event fires when an attempt is made to save the current row

    but there is no reason why you cannot put logic behind the print button..... check the data is correct before you allow the report tobe pritned.. check what code is runnign when you press the print button.

    Access has lots of wixzrds which do lots of things for you, but there is no need to likmit youirself to just what the Access designers build in, thats why they expose a wide range of events, or event hooks which trigger and if set will run code.


    when you add a comman button the Access wizard will add some code to that controls on click event. there is now stopping you intercetping that code and decidign what you want to do.

    the only caution I'd offer is that the modern visual interfaces its usually recommended that if a user cant do something then it should be clear on the form they can't do (by either disabling, hiding or other intervention so that you don't have display error messages
    I'd rather be riding on the Tiger 800 or the Norton

  8. #8
    Join Date
    Aug 2013
    Posts
    82
    Okay logically it would be better to put code behind the report "8130-3".

    What would be the simplest code to not have blank fields? Perhaps just highlighting these in yellow if they are blank when the user presses the print button and not allow the print to happen until these are filled out.

  9. #9
    Join Date
    Aug 2013
    Posts
    82
    Where should I put this code for the print button (command269)?


    If Not IsNull(Me.Technician) And Not IsNull(Me.Repairman) And Not IsNull(Me.TestEquipment) and Not IsNull(Me.Disposition) Then
    Me.Command269.Enabled = True
    Else
    Me.Command269.Enabled = False
    End If

  10. #10
    Join Date
    Aug 2013
    Posts
    82
    Could this be added to the code for On Click?

  11. #11
    Join Date
    Aug 2013
    Posts
    82
    I have this already in the On Click event:


    Private Sub Command269_Click()
    Dim strDocName As String
    Dim strWhere As String
    strDocName = "8130-3"
    strWhere = "[WorkorderID]=" & Me!WorkorderID
    DoCmd.OpenReport strDocName, acPrint, , strWhere
    End Sub

  12. #12
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    at what point do these fields become required?
    what is the trigger point.
    if that trigger point involves setting a value, then thats where I think I'd want to place soewm code
    Id' disable the print button until you have your required/relevant information
    so that means disabling the print button (or more accurately setting the print button's enabled satte0

    probably through a function eg:-
    public sub SetPrintButtonState()
    if (whatever your validation rules are) = true then
    myprintbutton.enabled = true
    mycotnrol.enabled = true
    else
    myprintbutton.enabled = false
    mycontrol.,enabled = false
    endif
    end sub

    the reason for pushing the code into a sub is that you cna then add whatever logic you need into the validation and call it form as amny palces as required
    then call that sub int he forms on current event and the forms before update event and the relevant controls before update event.. so you are covered for any eventuality that could trigger this.
    highlighting in yellow is all well and good, but it doesn't inhibit the print button being pressed


    so yuoumust have controls a....x validted if their is a finsihed date

    checkt he finished date is valid and sane
    if so enable those controls

    when those controls are also valid then enable the print button. users cant get to print a report until they have entered valid data in the finished date control and the other controls as required by your business riules
    I'd rather be riding on the Tiger 800 or the Norton

  13. #13
    Join Date
    Aug 2013
    Posts
    82
    There is no reason to print the "8130-3" until finished. I want to prevent this report from printing until those required fields are filled out.

  14. #14
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so your steps are
    disable subsequent controls and print button
    enable subsequent controls after finish date entered
    enable print button when subsequent control have valid data
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •