List Box Value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • benchpolo
    New Member
    • Sep 2007
    • 142

    #1

    List Box Value

    I have a form that contains client information such as client id, name, address etc. etc.

    Then I have another form which is a list box that contains the client id and name.

    What I’m trying to accomplish is that when I click a client id in the list box the form will load the detailed information of the client id that I choose from the list box.

    List Box (lclient) code
    Private Sub lclient_Click()
    'assign value to global variable
    gClientID = lclient
    'load form
    Dim sform As String
    sform = "W7"
    DoCmd.OpenForm sform, , , , acFormEdit
    End Sub

    Form Load Code
    Private Sub Form_Load()
    clientid.setfoc us
    clientid = gClientID
    End Sub

    PROBLEM: When the form loads it’s only changing the value of the clientid field the rest of the data are not.

    Please advise.

    Thanks.
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Why not just filter the opened form by [clientid]?

    Comment

    • benchpolo
      New Member
      • Sep 2007
      • 142

      #3
      That is not the spec of the project.

      A list box with the list of client refencing client id so when a user selects the client id another form will load and displays the client information based on the selected client id.

      Thanks.

      Comment

      • FishVal
        Recognized Expert Specialist
        • Jun 2007
        • 2656

        #4
        Originally posted by benchpolo
        That is not the spec of the project.

        A list box with the list of client refencing client id so when a user selects the client id another form will load and displays the client information based on the selected client id.

        Thanks.
        And the form opened has, let us say, [Clients] table as recordsource where [clientid] I guess is a PK field. So my "question" remains the same - why not just filter the form to display a single record where [clientid] is that selected with the listbox?

        If I'm getting something wrong, then please provide a clearer explanation of your situation.

        Kind regards,
        Fish

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          What you're missing, Fish, is

          "That is not the spec of the project."

          Since business people usually tell programmers what to do, not how to do it, I suspect that the person setting the "spec of the project" is a classroom instructor.

          You need to dump the global variable approach, as well as the Form_Load code and look at the fourth argument (WhereCondition) of OpenForm. The standard approach to this problem would be something like this:

          Code:
          Private Sub lClient_Click()
           Dim sform As String
           sform = "W7"
             DoCmd.OpenForm sform, , , "[ClientID] = '" & Me.lClient & "'", acFormEdit
          End Sub

          Comment

          Working...