• Conditional Formatting (Access 2000 – SR1)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Conditional Formatting (Access 2000 – SR1)

    Author
    Topic
    #362991

    Access 2000 has a nice little feature called Conditional Formatting which allows you to change the appearance of a field depending upon one of three conditions:
    Field Value is, Expression is or Field has focus.
    Here is the scenario: I have a continuous form which has three fields, Name , Phone Number and Fax Number:
    What I’ve been attempting to do is create an “Expression is” in the Phone Number and Fax Number fields which will change their colours if Name has “GotFocus”, ie. Someone has put their sticky little cursor on it.

    I’ve tried: Iif(Has GotFocus([Name]),Visible=True,Visible=False)
    and several variations, give or take the odd paranthesis, on the same theme. The VBA gods just laughed at me. I would appreciate any suggestions. Thanks in advance.

    Viewing 1 reply thread
    Author
    Replies
    • #552635

      Could you put the code in the GotFocus event of the Name field instead of in the Phone Number and Fax Number fields? PhoneNumber.visible=true. Then in the LostFocus event code for Name: PhoneNumber.visible=false

      • #552669

        Dottie:
        Thanks for your response. Your solution would be bang on if I only wanted the fields to disappear. I’m afraid my example was ambiguously worded. Check out Jayden’s answer, because, in spite of my efforts to confuse, he understood what I was attempting to do and came up with the answer. Thanks again for your suggestion.

        • #552735

          You’re welcome! I am glad that Jayden’s solution was exactly what you needed. I have just recently discovered The Lounge and also find it to be an amazing resource! I am learning so much from reading people’s solutions. Good luck with your project!

    • #552653

      The problem that you have with your expression is that you have not used the correct syntax.

      The first thing that you should probably do, is display the properties of the field that you wish to have the conditional formatting for. Then on then Event tab, double click next to the Got Focus event and then click the ellipsis button (the one to the right with three dots (…)). This will take you to the Visual Basic window for the Got Focus event of the control.

      It will probably look something like this

      Private Sub Name_GotFocus()

      End Sub

      Between these lines you will want to put your values that change the background colours of the phonenumber and fax number controls

      This would look something like this:

      PhoneNumber.BackColor = 255
      FaxNumber.BackColor = 255

      So the complete part of this will look like this

      Private Sub Name_GotFocus()
      PhoneNumber.BackColor = 255
      FaxNumber.BackColor = 255
      End Sub

      So what this would do, is that when the Name field gets the focus, the PhoneNumber and FaxNumber fields change their color to red. I’m not entirely sure why you are wanting to do this, but hey this should work if that is what you are trying to do.

      One last thing, as that I guess that you wish for these fields to return to their orginal colour when the Name control looses the focus again. So, you need to follow a similar proceedure for the Name control for it’s Lost Focus event.

      The LostFocus event for the Name control would look similar but have the background colour of the phonenumber and faxnumber controls put back to whatever colour they were orginially.

      Hope that this spreads some light on your problem.

      • #552670

        Jayden:
        Thanks for your solution which did answer my problem in spite of my efforts to confuse. I appreciate you taking the time to help out. Hopefully someone will ask an easy question that I can answer before the knowledgeable ones. Canada

        • #552714

          No problem, it’s always fun grin to help others out. I only wish that I had a resource like this when I was starting to learn Access, it would have reduced many hours trying to decipher the MS Help files.

    Viewing 1 reply thread
    Reply To: Conditional Formatting (Access 2000 – SR1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: