Results 1 to 9 of 9
  1. #1
    jadira is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    5

    checkbox dependent IIf function

    Hello. I'm needing some help with getting a field to produce either a "0" if a checkbox is marked or calculating a number. Here's the code I tried

    IIf( [Never Arrived] , "Yes", "0", "No" = ([End of Billing Cycle]-[Begin Billing Date]))

    I'm using information put into a form that then enters into a table. This code I have in a field called Length of Stay. I'm wanting to enter a 0 days if my check box is clicked, and if the check box is not clicked then I want to calculate the actual length of stay.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    You are working in a form? Why not use an if then else statement?

    If Me.CheckBoxName.Value = -1 then
    'It is checked
    Else if Me.CheckBoxName.Value = 0 then
    'It is not checked

    else
    'It is Null
    End if

  3. #3
    jadira is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    5
    This part is in a table. I've also tried:

    IIf([Never Arrived],"Yes",then = "0", IIf([Never Arrived],"No"=([End of Billing Cycle]-[Begin Billing Date]))

    Just started using ACCESS about a week ago.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Usually you would use an IIf() function in a query or a form. If you feel more comfortable working only in tables, you may be better served using Excel for this project. The general rule in Access is to use forms and reports as an interface for Users. So, store data in tables, use queries to support forms and reports, use forms as a graphical user interface to the data, and use reports to present historical and statistical data.

  5. #5
    jadira is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    5
    I have a checkbox in a form to indicate never arrived, but I'm just having difficulty translating the information I want to convey into my table correctly. I want to be able to make the value 0 in another column on my table if the checkbox is clicked on the form. if it's not, then I want it to subtract end date from begin date to indicate a length of stay.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I uploaded an example where a form is bound to a table. On there form are two controls that are bound to this table. One of the controls is a TextBox Control. The other control is a Checkbox control. If you click the Checkbox and change its value, the TextBox control Value changes also.

    Behind the form is some VBA that manages the AfterUpdate Event that is triggered when the User changes the value of the Checkbox control.

    Open the form in Design View.

    You can view the code behind the form by opening the VBA editor. The keyboard shortcut to open the VBA editor is Ctrl+G. Another way to open the editor is to click the ellipses (...) next to the appropriate event of the appropriate control. The Properties sheet has an Event tab where you can find the various events for a given control.

    .
    Click image for larger version. 

Name:	AfterUpdate.jpg 
Views:	20 
Size:	34.6 KB 
ID:	25759
    Attached Files Attached Files

  7. #7
    jadira is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    5
    maybe it would help if you saw this....I may just be over-complicating things
    Attached Files Attached Files

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    It looks like you built out an expression in your event for one of your checkboxes. Maybe VBA would be easier. Check out my example. It should not be too hard to understand once you look at the code.

  9. #9
    jadira is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    5
    turns out all i needed was to a simple code in my length of stay column

    IIf([Never Arrived],0,([End of Billing Cycle]-[Begin Billing Date]))

    I guess I should follow the KISS rule. (Keep It Simple Stupid)

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

Similar Threads

  1. Dependent ComboBoxes
    By HansJ in forum Forms
    Replies: 3
    Last Post: 06-09-2016, 05:12 PM
  2. Replies: 1
    Last Post: 11-26-2014, 02:30 PM
  3. Running code in function if checkbox is ticked
    By lewis1682 in forum Programming
    Replies: 7
    Last Post: 09-22-2013, 05:35 PM
  4. Help with dependent values
    By ceejsing in forum Access
    Replies: 6
    Last Post: 08-05-2011, 06:36 AM
  5. Dependent Combo Box
    By tigers in forum Forms
    Replies: 1
    Last Post: 06-16-2009, 12:46 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