Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2004
    Posts
    5

    Unanswered: passing a text box.

    Have a number of "Yes/No" files that I want to colorize.

    This code works, but I want to make it a procedure...

    Select Case Me.text1
    Case "No"
    Me.text1.ForeColor = RGB(255, 0, 0)
    Case "Yes"
    Me.text1.ForeColor = RGB(0, 255, 0)
    Case Else
    Me.text1.ForeColor = RGB(128, 128, 32)
    End Select


    The following does not work, How do I pass the textbox correctly?

    Sub Colorize_Format(Fred As Variant)
    Select Case Fred
    Case "No"
    Fred.ForeColor = RGB(255, 0, 0)
    Case "Yes"
    Fred.ForeColor = RGB(0, 255, 0)
    Case Else
    Fred.ForeColor = RGB(128, 128, 32)
    End Select
    End Sub

    Colorize_Format(Me.text1)


    Thanks for anyhelp you can offer.

    Dwayne

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Hmm... you want to pass the VALUE of the text box, as well as the textbox object...

    Sub Colorize_Format(frm As Form, Fred As TextBox, Value As String)
    Select Case Fred
    Case "No"
    frm.Fred.ForeColor = RGB(255, 0, 0)
    Case "Yes"
    frm.Fred.ForeColor = RGB(0, 255, 0)
    Case Else
    frm.Fred.ForeColor = RGB(128, 128, 32)
    End Select
    End Sub

    Colorize_Format(Me, Me.TextBox, Me.TextBox)

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    I got something workable going...

    Code:
    Sub Colorize_Format(frm As Form, txtName As String, Value As String)
    Select Case Value
    Case "No"
        frm(txtName).ForeColor = RGB(255, 0, 0)
    Case "Yes"
        frm(txtName).ForeColor = RGB(0, 255, 0)
    Case Else
        frm(txtName).ForeColor = RGB(128, 128, 32)
    End Select
    End Sub
    Usage:

    Colorize_Format Me, "yourTextBox", yourTextBox

    Edit:

    On second thought,

    Code:
    Sub Colorize_Format(frm As Form, txtName As String)
    Select Case frm(txtName)
    Case "No"
        frm(txtName).ForeColor = RGB(255, 0, 0)
    Case "Yes"
        frm(txtName).ForeColor = RGB(0, 255, 0)
    Case Else
        frm(txtName).ForeColor = RGB(128, 128, 32)
    End Select
    End Sub
    Usage:

    Colorize_Format Me, "yourTxtBox"
    Last edited by Teddy; 03-26-04 at 12:22.

  4. #4
    Join Date
    Mar 2004
    Posts
    5

    Me does not seam to be a form....

    Calling it from Detail_Format does not think Me is a frm. If I switch to Variant, getting an "can't find the field "ME.dev" referred in your expression." error. What is the object passed to detail_format? how do I get from it to the frm object?

  5. #5
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    If you're not calling the sub from you're target form, then you need to explicitly call the form and the text box string. I was able to test this code, it verifies good.

    eg:

    Colorize_Format forms!yourtargetform, "yourTxtBoxName"

  6. #6
    Join Date
    Mar 2004
    Posts
    5

    Thumbs up Thanks

    Thanks for yor help, The part I was missing is I was working with a report not a form. Once I updated the procedure to reflect this it work!

    On a side note my.textbox1.forecolor = RGB(100,100,100) works, but my.textbox1.backcolor=RGB(100,100,100) has not effect on the report. I'm running an access97, any idea why this does not shade the background? Is there an another/correct way to dynamicly set the background color of a textbox in a report?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •