Results 1 to 3 of 3
  1. #1
    sankalp88 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    1

    Help with IIf function in a data entry form!

    Hello!

    I'm a beginner in Access and currently working on a data entry form. We are using filled surveys to build a database. Here's my problem:

    We have a particular question which says: "Did you produce corn this year"? If yes, then the user needs to fill the acres, irrigated land etc. However if no, then we need to enter in nothing there and I want that particular entry box to be blocked off for the user. That is he can't enter any data at all!



    Here's how I was thinking about this problem.

    1. I create a Field, Corn, which is a Yes/No category.
    2. Then create two additional fields for acres, irrigated land. If the user answers "Yes" in the field Corn then he's allowed to enter the following two fields. If he answers "no" then the he can't enter anything in the next two fields.

    How do I go about doing this? I was thinking of the IIf function, but I don't know the correct syntax. Any place would be appreciated thanks!

    Sankalp

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    If you have a check box control bound to the field, Corn, then you could use some code in the After Update event of the check box. Something like:
    Me.AcresControl.Enabled = Me.ActiveControl
    Me.IrrigatedControl.Enabled = Me.ActiveControl

    EDIT:
    You may need the code in the Form's On Current event as well.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Code like Bob gave (and it definitely will need to be in the Form_Current event, as well as in the AfterUpdate event of the Checkbox) will work for a Single View Form, but will look odd for a Datasheet View or Continuous View Form. In those types of Forms, the Enabling/Disabling for the Acres and IrrigatedAcres Controls in the Current Record will be reflected in those Controls for all Records! So if the Checkbox is not ticked in the Current Record, those Controls will all appear greyed out for all Records, and vice versa.

    For Datasheet View and Continuous View Forms, you could use the Locked Property, instead of the Enabled Property, if you don't care about the Controls looking disabled, i.e. being 'greyed out,' but the best choice would be to use Conditional Formatting to Disable them. You'd

    1. Right-Click on the Textbox
    2. Click on Conditional Formatting
    3. Under Condition1 select Expression Is from the dropdown
    4. In the Condition Box enter [CheckboxName] = -1
    5. Click on the Enable/Disable Icon
    6. Click OK

    In Step #4 be sure to to include Square Brackets around the name of the Checkbox.

    Conditional Formatting can, of course, also be used for Single View Forms, as well.

    Linq ;0)>

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

Similar Threads

  1. Replies: 5
    Last Post: 08-12-2013, 12:53 AM
  2. Duplicate data message for a data entry form
    By JulieMarie in forum Access
    Replies: 5
    Last Post: 07-30-2013, 08:18 AM
  3. Data Entry Form
    By Stan Denman in forum Forms
    Replies: 1
    Last Post: 05-21-2013, 04:34 PM
  4. Data entry form
    By adept in forum Forms
    Replies: 1
    Last Post: 08-20-2010, 10:13 PM
  5. Sub Form Data Entry
    By OldBloke in forum Forms
    Replies: 1
    Last Post: 08-09-2010, 06:58 AM

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