Consulting

Results 1 to 6 of 6

Thread: form question

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    form question

    When I run the following code the background does not change.

    Private Sub Workbook_Open()
    UserForm1.txtAcctNum.BackColor = vbYellow
    End Sub


    Any ideas? Thanks
    Peace of mind is found in some of the strangest places.

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    That code runs when the workbook opens. It doesn't run when the userform opens. If it affected any userform, it would only be the first time that Userform1 was invoked.

    If you want that textbox permanently yellow, you can change the default color of the textbox to yellow in the Property Window. The same place that you changed its name.

  3. #3
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Sorry wasnt clear. When you first open the form i want the txtbox yellow. once someone types in it the color needs to go back to white. So where/how would i set that up?
    Peace of mind is found in some of the strangest places.

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    The Form's Initialize sub. It's available from the same VBA Dropdown that all the Controls' Event subs are in.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    i want the txtbox yellow. once someone types in it the color needs to go back to white
    I would set the default back color to yellow and then put this code in the userform's code module.

    Private Sub TextBox1_Change()
        TextBox.BackColor = vbWhite
    End Sub
    Although this might be what you want.
    Private Sub TextBox1_Change()
        With TextBox1
            If .Text = vbNullString Then
                .BackColor = vbYellow
            Else
                .BackColor = vbWhite
            End If
        End With
    End Sub

  6. #6
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Thanks . This one is Sorted.
    Peace of mind is found in some of the strangest places.

Posting Permissions

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