Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Join Date
    Jun 2002
    Location
    Houston, TX
    Posts
    116

    Unanswered: Form display based on item selected

    I have a form that has a combo box that a user can select an item. What I want is after they make their selection I want it to show a name for what they selected.

    For example the combo box has a a list of account number, so if they select #14 a text box would show the customer name - ABC Company. I'm sure I need to enter something in the event for "On Enter" but I have no idea how to write code.

    Thanks ... texasalynn

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    The simplest solution might be to have your combo box display both fields. Otherwise, what is the source for your form's data? Is the combo-box bound to a table field?

    blindman

  3. #3
    Join Date
    Jun 2002
    Location
    Houston, TX
    Posts
    116
    The combo box is from a table.

    texasalynn

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Yes, but what is the source for the form? Is it the same table that is a source for the combo box?

    blindman

  5. #5
    Join Date
    Jun 2002
    Location
    Houston, TX
    Posts
    116
    The form uses the table as source and the company names will come from the same table

    texasalynn

  6. #6
    Join Date
    Jun 2002
    Location
    Houston, TX
    Posts
    116
    My issue is the same and I can't get it to work.

    http://dbforums.com/t844801.html

    Thanks... texasalynn

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Your combo box uses the same datasource as the table? Are you trying to look up a record in your form based on what you select in your combo box, or are you trying to set a value in the table on which your form is based?

    If you think your problem is similar to alazarou's, send us the same informatiion:

    Column Count:
    Column Widths:
    Control Source:
    Row Source Type:
    Row Source: (cut and paste sql code please!)
    Bound Column:
    Limit To List:
    ...and any events associated with it along with their complete code.

    Also, please cut and paste the datasource sql for your form.

    blindman

  8. #8
    Join Date
    Jun 2002
    Location
    Houston, TX
    Posts
    116
    Originally posted by blindman
    Your combo box uses the same datasource as the table? Are you trying to look up a record in your form based on what you select in your combo box, or are you trying to set a value in the table on which your form is based?

    If you think your problem is similar to alazarou's, send us the same informatiion:
    Name:Combo22
    Column Count: 2
    Column Widths: 0.448";0"
    Control Source: is blank
    Row Source Type: Table/Query
    Row Source: (cut and paste sql code please!) SELECT cbs_accts_finaled.CBS_NO, cbs_accts_finaled.[National Account Name]
    FROM cbs_accts_finaled;

    Bound Column: 1
    Limit To List: Yes
    ...and any events associated with it along with their complete code.

    Also, please cut and paste the datasource sql for your form.

    blindman
    I have put the answers above for each

    texasalynn

  9. #9
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    OK, since your combobox is not bound to any field on your form's datasource, I assume you are trying to lookup a value (move to a particular record) based on what you enter into the combo box. I could step you through creating the VB code necessary to do this, but really it would probably be simpler for you to add a new combo box to your form, and when prompted by the combo box wizard choose the "Find a record on my form..." option.

    There are some other curious things about the combo box you have. The second column's width is set to zero, so it will never be visible, and it is not the bound column, so I can't see what use it is at all. If you want to be able to see [National Account Name] in the dropdown list, set its width to something greater than 1. (You still won't be able to see it after your selection is made, as only one column can be displayed in your combo box).

    blindman

  10. #10
    Join Date
    Jun 2002
    Location
    Houston, TX
    Posts
    116
    Sometimes I find it so hard to explain without visuals. I'm sorry I haven't drawn the picture well enough.

    My combo box is hooked to a table
    The combo provides the accounts for the user to select from
    The text box is to show the name based on what account is selected.

    The suggestions have been on the right track and I'm sure that I have done something silly, but it's not clicked yet.

    Thanks for your continued input and don't quit yet.

    texasalynn

  11. #11
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Your little crying smiley-face icon continues to elicit my sympathy, so here goes:

    I don't understand why you have a separate text box to display the associated [National Account Name] for the CBS_NO value you select in your combox box, but if you want to set it you can use VB code.

    From your combobox properties, go to the events tab and select the ON CHANGE event.
    Choose the CODE BUILDER option, and in write your subrouting like this:

    Private Sub Combo22_Change()
    [YourTextBox] = dlookup("[National Account Name]", "cbs_accts_finaled","[CBS_NO] = " + Me.Combo22)
    End Sub

    If CBS_NO is text field rather than numeric, you will need to embed single quotes like this:

    [YourTextBox] = dlookup("[National Account Name]", "cbs_accts_finaled","[CBS_NO] = '" + Me.Combo22 + "'")


    blindman

  12. #12
    Join Date
    Jun 2002
    Location
    Houston, TX
    Posts
    116
    I get a type mismatch on that line of code.


    texasalynn

  13. #13
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Did you try the second version?

    blindman

  14. #14
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    sounds like she is trying to display a value other than the bound column

    is that correct

    the bound column being the acctnumber ?

  15. #15
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Yes I think that's what she is looking for, which is why I gave her the dlookup statement.

    I'm concerned about her form design though if she is setting a field value in a table useing a lookup which is based on the same table. In a normal(ized) database design, these lookups would be based on separate tables.

    blindman

Posting Permissions

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