Populate a text box based on list box selection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • almaroc
    New Member
    • Nov 2011
    • 48

    Populate a text box based on list box selection

    I have a list box of company names and i need to populate a text box with the corresponding value from the usage field.
    my table is named Average. the fields are Customer and Usage. i used this code in the AfterUpdate event of the list box. i cannot get the text box to populate.here is the code
    Code:
    Private Sub Cust_ListS_AfterUpdate()
    
        With Me
            .txt_AvgS = DLookup(Expr:="[Usage]", _
                             Domain:="[Average]", _
                            Criteria:="[Customer] = '" & .Cust_ListS & "'")
       End With
    End Sub
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    The best way to debug such a thing is to start by checking that your criteria is set correctly. Try this in your code:
    Code:
    Dim strCrit as string
    strCrit="[Customer] = '" & .Cust_ListS & "'"
    Msgbox strCrit
    And look at what the msgbox tells you. It will give us something to work from.

    Comment

    • almaroc
      New Member
      • Nov 2011
      • 48

      #3
      thanks Smiley that did the trick.

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        Im glad to hear that, however for this forum to supply the best value, it would be nice if you could explain in more detail how it worked on your particular problem, for anyone else who might come along and find this thread.

        Comment

        • almaroc
          New Member
          • Nov 2011
          • 48

          #5
          Well. after i looked at the value returned by the listbox. i found out that it was the CustomerID field instead of CustomerName. so I changed the field in my Dlookup criteria.

          Comment

          Working...