Results 1 to 9 of 9
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919

    Coding Conditional Formatting

    Here's an image showing this simple form with simple "Conditional Formatting" specifications to the selected text box.
    Click image for larger version. 

Name:	CondFormat.jpg 
Views:	18 
Size:	158.2 KB 
ID:	13815

    gblRetID is a global string variable that is defaulted to the name of the current user. When the user invokes a function that displays the form you see in the image above, the code:

    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub Form_Click()
    gblRetID = Me.retID
    End Sub
    runs when the user selects an entry in the form's list of choices, namely alternative envelope return addresses. I've verified the value of gblRetID when the OnClick event runs but the conditional formatting does not take affect. I "hard-coded" a string in the conditional formatting expression and the conditional formatting specification works fine, it's only when the use of [gblRetID] is used that the "match" does not take affect. (Me.retID is a reference to the value to which the TB is bound.)



    I don't know how much simpler this case could get, yet I'm not seeing what the problem is.

    Ideas? (Be gentle now)

    Bill

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Would it help to put this in the form's Load event verses Form Click?

    gblRetID = Me.retID

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    glbRetID is set when the app starts. The form is provided via a customized right-click option so the user can change the return address if a situation requires it subsequently.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    So then should it be

    Me.retID = gblRetID

    What is a typical literal value of Me.retID?

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    The RecordSource of the continuous popup form is a table of return addresses that are identified by a name in the "retID" field of each record, e.g., "Joe". When the app starts, the username is obtained via environment$("username") and the user name is assigned to the global variable "gblRetID". With that, the default return address is that of the current user. Since the user might have several different forms of their return address, he or she has the option of effectively changing the setting for the current session. E.g., "Joe" might be "Joe Blow" as the default for "Joe" but there's a record for a more formal form of Joe's name, like "Dr. Joesph Blow, MD" that he uses when creating an envelope he'll be using as part of his profession.

    So, to answer your question, no, glbRetID is already set at entry to the form. I want the ID of the current return address to be highlighted so that the user knows what is in effect. And, if they click on a different form of a return address I want the newly identified return addresses ID to highlight as an acknowledgement of what is to now be the return address on any subsequent envelopes.

    By the way, I can't get Conditional Formatting to work on ANY of the text-box controls.............I'm stumped!

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    I mean Environ$("Username"), NOT environment$

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    Update: I can't get any of the app's text-box controls to respond to conditional formatting on forms, continuous OR single record. I can IF I use a literal quoted string, but not when comparing control's value with a [variable].

    I also executed the app on a A2007 system but still get the failure(s).

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by GraeagleBill View Post
    Update: I can't get any of the app's text-box controls to respond to conditional formatting on forms, continuous OR single record. I can IF I use a literal quoted string, but not when comparing control's value with a [variable].

    I also executed the app on a A2007 system but still get the failure(s).
    This result is what I suspected when I studied your screen shot. I was not entirely understanding the components of your actions though. It seems creating a macro to handle your variable will be difficult. Why not code the conditions of your format requests entirely in VBA? Based on your quote here, you will need to convert your variable to a literal string and then pass your literal string to the macro. At that point, why bother passing it to the macro?

    On a side note, I like to take global variables and pass them to an unbound control ASAP. It just makes me feel good. Also, when in development and debugging, I don't have to step back very far and grab the global value every time I debug an error.

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    I'm not going to spend anymore time on this. I have alternate methods I use in identifying current selects, (see sample image below). The alternate method is just a little bit more involved and with the current app I initially didn't want to take the time. But, as it turns out, I would have been quite a bit ahead had I used that/this method to begin with.

    As for the use of global variables, I only use them when multiple forms, reports and general/class modules have common need of a value(s). One just needs to launch their app in such a way as the containing module is part of the load for the duration of the app.

    Click image for larger version. 

Name:	Sample.jpg 
Views:	13 
Size:	23.1 KB 
ID:	13835

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

Similar Threads

  1. Replies: 6
    Last Post: 05-26-2013, 09:10 PM
  2. Conditional Formatting
    By riaarora in forum Access
    Replies: 6
    Last Post: 09-03-2012, 05:58 AM
  3. conditional formatting
    By michele in forum Forms
    Replies: 6
    Last Post: 02-01-2012, 01:16 PM
  4. Conditional Formatting
    By Desstro in forum Programming
    Replies: 3
    Last Post: 12-01-2010, 09:52 PM
  5. Conditional Formatting
    By DanOzDirect in forum Reports
    Replies: 3
    Last Post: 07-21-2010, 08:49 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