Results 1 to 15 of 15
  1. #1
    DataRick is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2012
    Location
    Boyertown, PA
    Posts
    8

    Question Conditional formatting inside a form

    I am trying to set a conditional format for a required field based on the value of another field from the same table. I am trying to do this from the form that inputs the data in to the table.



    In other words, if the value of field A = 2, I want the value of the required field to be "yes" or "no" (this is a user input). If the value of field A is not 2, then the value of the required field is null.

    I've been experimenting with Iif statements for several hours and I'm at a loss. I am familiar with the basics of SQL but this seems to be beyond my expertise.

    Any help would be greatly appreciated!!


  2. #2
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Here is MS tutorial on how to do conditional formatting in a form.

    http://office.microsoft.com/en-us/ac...010208133.aspx

    Alan

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Wait! That is not conditional formatting, it is conditional value. This is a data validation issue. It will require VBA code to control the user input or if user is even allowed to do input. Is the required field a text or yes/no type?
    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.

  4. #4
    DataRick is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2012
    Location
    Boyertown, PA
    Posts
    8
    Thank you but that only applies to changing the color of the field. I need to force the user to enter a specified value of yes or no in the required field if the value of field A is 2.

  5. #5
    DataRick is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2012
    Location
    Boyertown, PA
    Posts
    8
    Yes. The required field is a text field and I want to force the user to enter "yes" or "no" if the value of field A = 2 (field A is not the required field but another field in the same table).

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    First I would control availability of the conditional field. Set the bound control as Enabled (or Visible) No. The in AfterUpdate event of FieldA:

    If Me.FieldA = 2 Then
    Me.controlname.Enabled = True
    Me.controlname.SetFocus
    End If

    Also use Validation property of the control: "Yes" Or "No"
    Once the control has focus, must enter Yes or No. Could be a combobox.

    Is this form in Single, Continuous, or Datasheet view? Can users navigate to other records?
    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
    DataRick is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2012
    Location
    Boyertown, PA
    Posts
    8
    The form is single and users can navigate to other records. I know very little about VBA. I like your idea of controlling the availability of the conditional field though. Can you point me to some step by step instructions for this? I think I might know but, like I said, VBA is relatively new to me.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Review this article http://office.microsoft.com/en-us/ac...010341717.aspx

    Will also need my suggested code in the form Current event so it will reset the Enabled property when moving to another record.

    If Me.FieldA = 2 Then
    Me.controlname.Enabled = True
    Me.controlname.SetFocus
    Else
    Me.controlname.Enabled = False
    End If
    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
    DataRick is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2012
    Location
    Boyertown, PA
    Posts
    8
    Thank you June7!! I will work on this this afternoon and let you know how I make out.

  10. #10
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Good catch June. I have been sick this weekend and I must have lost focus. Easy to do. I guess I should stay out of the forums until this passes so I don't mess anyone else up.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Hey Alan, is okay, I had to read it 3 times before it sunk in what the issue really was.
    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.

  12. #12
    DataRick is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2012
    Location
    Boyertown, PA
    Posts
    8
    I get this error when moving from one record to the next:
    Run-time error '2110':
    Rerun Tracker can't move focus to the control PJMfault.

    This is my code:
    Private Sub Form_Current()
    If Me.IMRRPBRR = 2 Then
    Me.PJMfault.Enabled = True
    Me.PJMfault.SetFocus
    Else
    Me.PJMfault.Enabled = False
    End If
    End Sub

    Private Sub PJMfault_AfterUpdate()
    If Me.IMRRPBRR = 2 Then
    Me.PJMfault.Enabled = True
    Me.PJMfault.SetFocus
    End If
    End Sub

    Here is what the terminology means:
    Rerun Tracker is the name of the database system

    IMRRPBRR is a number field in the table. On the form, I have an option box where the user must make 1 of 2 choices. The choices enter a value of 1 or 2 in the IMRRPBRR field. The default value is 1. I previously referred to this as FieldA.

    PJMfault is a text field name in the same table. I referred to this as the required field. If the value of IMRRPBRR is 2, I want to require the user to enter a value of "Yes" or "No" in this field.

    I'm thinking that I need to add a line in the else statement that sets the focus back to IMRRPBRR. Am I on the right track here?

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    That could be. If the focus was still on that control when moving to new record, it will try to stay there but it has been disabled, hence the error. Try it. Set focus before disabling.

    Also, might want to include the Else in the AfterUpdate so that if user unselects 2 the control will again be disabled.
    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.

  14. #14
    DataRick is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2012
    Location
    Boyertown, PA
    Posts
    8
    I'm almost there. Many, many thanks to June7 for all your help!!!

    **This determines if PJMfault is visible on an existing record**
    Private Sub Form_Current()
    If Me.IMRRPBRR = 2 Then
    Me.PJMfault.Visible = True
    Else
    Me.IMRRPBRR = 1
    Me.PJMfault.Visible = False
    End If
    End Sub

    **This makes PJMfault visible if IMRRPBRR is changed from 1 to 2 when entering a new record**
    Private Sub Frame7_AfterUpdate()
    If Me.IMRRPBRR = 2 Then
    Me.PJMfault.Visible = True
    Me.PJMfault.SetFocus
    End If
    End Sub

    The last thing I need to get working is to force the user to enter yes or no in the PJMfault field when it is visible on the form.

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Set Validation property to: Yes Or No. Unfortunately, validation probably won't be enforced if user doesn't type in the field. Try code in the LostFocus event of this control.
    If Me.IMRRPBRR = 2 And Me.PJMfault & "" = "" Then
    MsgBox "Must select Yes or No."
    Me.PJMfault.SetFocus
    End If
    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.

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

Similar Threads

  1. Conditional Formatting
    By ccordner in forum Reports
    Replies: 6
    Last Post: 01-09-2012, 04:12 PM
  2. Conditional Formatting
    By Desstro in forum Programming
    Replies: 3
    Last Post: 12-01-2010, 09:52 PM
  3. Conditional formatting on form
    By ngruson in forum Forms
    Replies: 11
    Last Post: 09-17-2010, 12:15 PM
  4. conditional formatting right(..)
    By bbeernaert in forum Access
    Replies: 3
    Last Post: 08-25-2010, 12:33 AM
  5. Conditional Formatting (on Open form?)
    By christopheb in forum Forms
    Replies: 0
    Last Post: 03-16-2010, 07:07 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