Consulting

Results 1 to 7 of 7

Thread: Solved: TextBox BackColor when Enable

  1. #1
    VBAX Contributor
    Joined
    Mar 2009
    Location
    Porto, Portugal
    Posts
    180
    Location

    Solved: TextBox BackColor when Enable

    Hi
    May be I dont get it because I'm already thinking of "night reveillon"
    so I'm asking a little help, if You please

    The code below works on a userform (frmAlterar) and it setups enable/disable textboxes of another userform (frmRegisto) by choosing one of the buttons.

    This works very fine.

    The problem is that the enabled textboxes appear with Backcolor in BLACK and I would want to be the default color of textbox when enable (White).

    How do I fix that?

    [VBA]Private Sub HabilitaControles2() 'CORRIGIR DADOS
    frmRegisto.txtNOME.Locked = False
    frmRegisto.txtTIPO.Locked = False
    frmRegisto.txtMATERIAL.Locked = False
    frmRegisto.txtMARCA.Locked = False
    frmRegisto.txtMODELO.Locked = False
    frmRegisto.txtDN1.Locked = False
    frmRegisto.txtDN2.Locked = False
    frmRegisto.txtPN.Locked = False
    frmRegisto.txtDATA.Locked = False
    frmRegisto.txtLOC.Locked = False
    frmRegisto.txtPRECOUNIT.Locked = False
    frmRegisto.txtRESPONSAVEL.Locked = False
    frmRegisto.txtOBS.Locked = False

    frmRegisto.txtNOME.BackColor = corEnabledTextBox
    frmRegisto.txtTIPO.BackColor = corEnabledTextBox
    frmRegisto.txtMATERIAL.BackColor = corEnabledTextBox
    frmRegisto.txtMARCA.BackColor = corEnabledTextBox
    frmRegisto.txtMODELO.BackColor = corEnabledTextBox
    frmRegisto.txtDN1.BackColor = corEnabledTextBox
    frmRegisto.txtDN2.BackColor = corEnabledTextBox
    frmRegisto.txtPN.BackColor = corEnabledTextBox
    frmRegisto.txtDATA.BackColor = corEnabledTextBox
    frmRegisto.txtLOC.BackColor = corEnabledTextBox
    frmRegisto.txtPRECOUNIT.BackColor = corEnabledTextBox
    frmRegisto.txtRESPONSAVEL.BackColor = corEnabledTextBox
    frmRegisto.txtOBS.BackColor = corEnabledTextBox
    End Sub

    Private Sub HabilitaControles3() 'ENTRADA DE MATERIAIS
    frmRegisto.txtENTRADAS.Locked = False
    frmRegisto.txtDATA.Locked = False
    frmRegisto.txtPRECOUNIT.Locked = False
    frmRegisto.txtORIGEM.Locked = False
    frmRegisto.txtRESPONSAVEL.Locked = False
    frmRegisto.txtOBS.Locked = False

    frmRegisto.txtENTRADAS.BackColor = corEnabledTextBox
    frmRegisto.txtDATA.BackColor = corEnabledTextBox
    frmRegisto.txtPRECOUNIT.BackColor = corEnabledTextBox
    frmRegisto.txtORIGEM.BackColor = corEnabledTextBox
    frmRegisto.txtRESPONSAVEL.BackColor = corEnabledTextBox
    frmRegisto.txtOBS.BackColor = corEnabledTextBox
    End Sub

    Private Sub HabilitaControles4() 'SAIDA DE MATERIAIS
    frmRegisto.txtSAIDAS.Locked = False
    frmRegisto.txtDATA.Locked = False
    frmRegisto.txtPRECOUNIT.Locked = False
    frmRegisto.txtDESTINO.Locked = False
    frmRegisto.txtRESPONSAVEL.Locked = False
    frmRegisto.txtOBS.Locked = False

    frmRegisto.txtSAIDAS.BackColor = corEnabledTextBox
    frmRegisto.txtDATA.BackColor = corEnabledTextBox
    frmRegisto.txtPRECOUNIT.BackColor = corEnabledTextBox
    frmRegisto.txtDESTINO.BackColor = corEnabledTextBox
    frmRegisto.txtRESPONSAVEL.BackColor = corEnabledTextBox
    frmRegisto.txtOBS.BackColor = corEnabledTextBox
    End Sub

    Private Sub CommandButton1_Click()
    With frmRegisto
    Call HabilitaControles3
    End With
    frmAlterar.Hide
    End Sub

    Private Sub CommandButton2_Click()
    With frmRegisto
    Call HabilitaControles4
    End With
    frmAlterar.Hide
    End Sub

    Private Sub CommandButton3_Click()
    With frmRegisto
    Call HabilitaControles2
    End With
    frmAlterar.Hide
    End Sub
    [/VBA]

    Note: corEnabledTextBox appears in the project code as Constant, like the following:
    [VBA]Const corDisabledTextBox As Long = -2147483633
    Const corEnabledTextBox As Long = -2147483643[/VBA]

    In spite of I have copied this from another code, that dont affect any of similar subs of the entire project.
    The backcolor in BLACK only appears in this three subs (HabilitaControles2, HabilitaControles3 and HabilitaControles4)

    Thanks in advance and HAPPY NEW YEAR
    Ioncila

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Const corDisabledTextBox As Long = -2147483633
    Public Const corEnabledTextBox As Long = -2147483643
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor
    Joined
    Mar 2009
    Location
    Porto, Portugal
    Posts
    180
    Location
    Quote Originally Posted by xld
    [vba]

    Public Const corDisabledTextBox As Long = -2147483633
    Public Const corEnabledTextBox As Long = -2147483643
    [/vba]
    Thanks for reply
    There is a problem however wiyh your suggestion:

    It returns
    Compile error:
    Constants, fixed-lenghtstrings, arrays, ... not allowed as Public members of object modules.


    I only added 'Public' before Const, as you mentioned.
    Do I have to do Something more?

    Project code begins like that:
    [VBA]Option Explicit

    Const colCOD As Integer = 1
    Const colNOME As Integer = 2
    Const colTIPO As Integer = 3
    Const colMATERIAL As Integer = 4
    Const colMARCA As Integer = 5
    Const colMODELO As Integer = 6
    Const colDN1 As Integer = 7
    Const colDN2 As Integer = 8
    Const colPN As Integer = 9
    Const colENTRADAS As Integer = 10
    Const colSAIDAS As Integer = 11
    Const colEXISTENCIAS As Integer = 12
    Const colDATA As Integer = 13
    Const colLOC As Integer = 14
    Const colPRECOUNIT As Integer = 15
    Const colVALORTOTAL As Integer = 16
    Const colORIGEM As Integer = 17
    Const colDESTINO As Integer = 18
    Const colRESPONSAVEL As Integer = 19
    Const colOBS As Integer = 20

    Const indiceMinimo As Byte = 2
    Const corDisabledTextBox As Long = -2147483633
    Const corEnabledTextBox As Long = -2147483643

    Private wsCadastro As Worksheet
    Private indiceRegistro As Long[/VBA]

    Happy New Year
    Ioncila

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Which module are those constants declared in?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Contributor
    Joined
    Mar 2009
    Location
    Porto, Portugal
    Posts
    180
    Location
    There are in "frmRegisto" code

  6. #6
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by ioncila
    There are in "frmRegisto" code
    Hi there :-)

    Just cuz Bob's most likely counting sheep...

    Move them to the top of a Standard Module.

    Mark

  7. #7
    VBAX Contributor
    Joined
    Mar 2009
    Location
    Porto, Portugal
    Posts
    180
    Location
    Quote Originally Posted by GTO
    Hi there :-)

    Just cuz Bob's most likely counting sheep...

    Move them to the top of a Standard Module.

    Mark
    Thank you very much.

    Its done and solved.

    Happy New Year
    Ioncila

Posting Permissions

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