Results 1 to 11 of 11
  1. #1
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2002
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    Reference 3 fields so that all 3 are not null

    Ok, I have 3 fields on my form named, OnCallDte OnCallNexttDte and finally OnCall



    both OnCallDte and OnCallNexttDte are date fields and cant have a null value if user checks the checkbox which is name OnCall Yes/No value. Also if user checks the checkbox then dates are necessary so that finally all 3 are required.

    So my dilemna is that how do I make it so all 3 are necessary. Itried the below code, but it obviously does not work since it wont allow anything. I am close but no banana.

    If IsNull([OnCallDte] Or [CallNexttDte]) Then ' Checks to see if date fields are Null
    [OnCall] = False
    MsgBox "If Employee On Call Status is Yes, Then Start and End Dates Are Required"
    End If


    Also tried this but did not work. I am referring to a sub-form from my main form. Main form is Employees_on_Call_What_Order

    'If Forms!Employees_on_Call_What_Order!Forms!frm_Eligi ble_For_On_Call![eligible] = True And [OnCall] = True Then
    '[OnCallDte].Enabled = True And [CallNexttDte].Enabled = True
    'End If



    __________________________________________________ ____________________
    Will this work ???

    If Not IsNull(DLookup("OnCallDte", "Employees", "OnCall = True AND "CallNexttDte" , 'Employees",)) Then
    MsgBox "Date Fields Must Have a Date"
    Cancel = True
    End If
    Else
    If Not IsNull (DLookup("OnCallDte", "Employees", AND "CallNexttDte Then
    MsgBox "OnCall Box Must Be Checked."
    Cancel = True
    End If

    If [OnCall] = True Then ' Checks to see if checkbox is set to yes
    [OnCallDte].Value = Null
    [CallNexttDte].Value = Null
    MsgBox ""
    End If
    Last edited by burrina; 10-24-2012 at 11:47 AM. Reason: Tried Code,More Failed Code

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What event do you have this code in? The checkbox Change event? Review this recent thread on similar issue https://www.accessforums.net/forms/c...ion-29218.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2002
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    It is on the main forms current event which is named Employees_on_Call_What_Order

    Since that is where the fields are located that that must not be null, all 3 if both date fields are not null then checkbox must be true and if checkbox is true both date fields must not be null. or any combination.

    __________________________________________________ ____
    What I am trying to accomplish is this; If a employee is eligible to be on call and they have their status set to be on call and they also have their start and end dates containing a value then all is well.

    The 4 fields that must have there criteria met are; OnCall and eligible, both of these are Yes/No checkboxes.
    And the 2 other fields are OnCallDte and CallNexttDte and both of these are date fields.

    So I need to check that all 4 criteria have been met. Otherwise cant save record or fields dimmed out or something so as to not allow it.
    Last edited by burrina; 10-24-2012 at 12:28 PM. Reason: Further Explanation

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    DLookup should not be necessary (syntax is wrong anyway). The fields are on the form and are therefore available for reference by code.

    What do you mean by 'wont allow anything'?

    The If IsNull Then syntax is wrong. Try:

    If IsNull(Me.OnCallDte) Or IsNull(Me.CallNexttDte) Then ' Checks to see if date fields are Null

    Step debug. Refer to link at bottom of my post for debugging guidelines.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2002
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    4 Fields MUST not be Null

    I just meant That really 4 fields must contain a value. The employee must be eligible, i.e. eligible = True , the employee must be be checked off as to be on call, OnCall = True
    and both date fields must contain a date, i.e. OnCallDte and CallNexttDte
    Attached Thumbnails Attached Thumbnails OnCallMustHaveFields.jpg  

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Did you try revised code?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2002
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Yes, it did not work, can I send DB for you too look at? Will this help?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Yes, follow instructions at bottom of my post. Indicate which objects are involved in issue.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2002
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    Attached Database

    Ok, here is the db. Please take a look at the OnCurrentEvent code for the main form where I have tried all kinds of code.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    So 'main form' is frm_Employees_on Call_What_Order?

    There is only one table in the db. All queries are based on this one table. All forms and subforms essentially have the same data source or are unbound. Never seen anything like this.

    The Eligible (misspelled as Eligibile in label) field is on subform but then is also in the main form RecordSource but for some reason code is not recognizing the main form field. This form opens filtered to only those employees who are eligible. Can't refer to the Eligible field in subform because it might not be on the same employee record that the main form is on. Consider this code in Current event:
    Code:
    Private Sub Form_Current()
    With Me
    .OnCallDte.Enabled = .OnCall
    .CallNexttDte.Enabled = .OnCall
    If .OnCall = True Then
        If IsNull(.OnCallDte) Or IsNull(.CallNexttDte) Then
            MsgBox "Both OnCall Start and End boxes must have a date"
        End If
    End If
    If Date >= .Set_On_Call_Week_Day_Date!one And Date <= .Set_On_Call_Week_Day_Date![seven] Then
        .Next_Weeks_Start_End_Days.Enabled = False
        .Following_Weeks_On_Call_Period.Enabled = False
        .Final_Weeks_On_Call_Period.Enabled = False
    End If
    End With
    End Sub
    If Eligible status is changed to False then run code in its Change event to set Oncall to False, remove dates, disable controls, and refresh forms.

    If Oncall status is changed then run code in its Change event to remove dates and disable boxes or notify user needs dates and enable boxes.

    What is Check6 for?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2002
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Check6 is an update query that sets all employee on call status to NO. I am trying code now. Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Is Not Null...Multiple fields
    By msk7777 in forum Access
    Replies: 13
    Last Post: 11-17-2011, 02:52 PM
  2. Combine two fields, Null fields involved
    By yes sir in forum Access
    Replies: 9
    Last Post: 10-03-2010, 09:20 AM
  3. Dynamic fields reference
    By tuna in forum Forms
    Replies: 0
    Last Post: 05-04-2010, 11:47 PM
  4. Replies: 5
    Last Post: 03-20-2010, 08:30 AM
  5. Wrong reference with .fields in DAO recordset
    By ddd in forum Programming
    Replies: 1
    Last Post: 12-08-2009, 05:34 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