How to reference a field in a specific table?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jim Petrin
    New Member
    • Feb 2011
    • 5

    How to reference a field in a specific table?

    I have a combo box in a form and want the background color to change if the name is female. Below is my code but nothing changes.

    I'm new at this and this is basic but I'm good at figuring things out if I'm put in the right direction, Please help.

    Code:
    Private Sub Combo5_Change()
    If [bowlers]![m/f] = "female" Then
    [Combo5].BackColor = "65535"
    Else
    [Combo5].BackColor = "16777215"
    End If
    
    End Sub
    Last edited by NeoPa; Feb 3 '11, 04:39 PM. Reason: Please use the [CODE] tags provided
  • mshmyob
    Recognized Expert Contributor
    • Jan 2008
    • 903

    #2
    Since the backcolor property is a long number you do not need to enclose the value in quotes.

    cheers,

    Comment

    • Jim Petrin
      New Member
      • Feb 2011
      • 5

      #3
      Now Microsoft access error says in can't find the field. Am I referencing the field properly? Or do I have to first activate the table?

      Code:
      Private Sub Combo5_Change()
      If [bowler]![gender] = "female" Then
      [Combo5].BackColor = 65535
      Else
      [Combo5].BackColor = 16777215
      End If
      Last edited by NeoPa; Feb 3 '11, 04:40 PM. Reason: Please use the [CODE] tags provided

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32653

        #4
        Jim, What are you trying to check? The value of the ComboBox?

        The event you should be using is the AfterUpdate event BTW.

        Here's some example code that may be along the right lines, but you need to explain your situation better if you hope to get pertinent help :
        Code:
        Private Sub Combo5_AfterUpdate()
            With Me.Combo5
            	.BackColor = IIf(.Value = "Female", 65535, 16777215)
            End With
        End Sub

        Comment

        • Jim Petrin
          New Member
          • Feb 2011
          • 5

          #5
          I tried your suggestion but that's not what I am trying to check. I'm trying to check the value of the field [Gender] which is located in the same table as the name in the combo box. The table name is [Bowlers].

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32653

            #6
            It wasn't a suggestion Jim. It was an illustration of concept. I also pointed out that more apposite help is unlikely without some more information coming from yourself.

            While your latest post is some more information, it is little more than an indication of what cannot be relied upon. I now know it's not that particular control that you need to refer to, but you give no clue as to whether there is another control on the form that can be referenced, or alternatively, if a separate reference to a table is indeed required (which is unusual), how the specific record in that table could be identified.

            The point I was making wasn't unimportant. I suggest you need to consider that before posting again. We're generally willing to help, but you need to put some effort in, even if it's only to explain your situation clearly enough so that we know what the question is.

            Comment

            • mshmyob
              Recognized Expert Contributor
              • Jan 2008
              • 903

              #7
              Jim you are referencing the field in the table incorrectly.

              The easiest way to reference the field is to have the table bound to the form and then place a text box control on the form that is bound to the gender field. As you move through the records in the table using the form the value in the text box control will update based on the value in the table records automatically. You can then check the status of the text box control on the form anytime you wish. If you do not want the text box control to be seen just set the visible property to false.

              Does this make any sense to you?

              cheers,

              Comment

              • Jim Petrin
                New Member
                • Feb 2011
                • 5

                #8
                Thank you mshmyob. That is very helpful. As evident I'm not a developer and trying to make access work for a youth bowling tournament and make our life easier on the paperwork side. This will set me in the right direction.

                Comment

                • mshmyob
                  Recognized Expert Contributor
                  • Jan 2008
                  • 903

                  #9
                  Good luck. If you have any other questions we will be here to hopefully answer them to your satisfaction.

                  cheers,

                  Comment

                  Working...