Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2003

    Unanswered: Changing Records using combo box

    Hi again,

    I'm still new at this, so don't hesitate to tell me I'm way off in my approach or give better ways.

    I have a form with a combo box that is linked to the Primary Key(Program Names) in one of my tables.

    I want to allow the user to select a "Name" from the combo box and have the information on the rest of the form change to match that record, or allow the user to input a new name.

    I have tried the following three things, but either have problems with the syntax or with the error of creating a duplicate Primary Key. How would you go about this

    Private Sub Name_of_P_P_Change() ' Run on Combo box change

    Dim Tempstring As String ' Get Combo Box text
    Tempstring = Name_of_P_P

    __________________________________________________ _________

    Form.Filter = [Program Names.Name of Program] = Tempstring

    Problem - Doesn't filter out records, Primary Key Duplicated
    __________________________________________________ _________
    #2 - DoCmd.GoToRecord - thought this was it, but could not get syntax

    'The current record had been passed from another form via a filter

    DoCmd.GoToRecord ([acDataTable],[Program names],[acGoTo

    Problem - I could never figure out the syntax

    #3 Run Query

    Dim stDocName As String
    stDocName = "Query7"
    DoCmd.OpenQuery stDocName, acNormal, acEdit

    ----- Query7 Has the the field "Program Names"
    Criteria - Tempstring

    Thank you for any help you can offer.


  2. #2
    Join Date
    Jul 2003
    Don't know if this will be much help or not...

    Personally, I would use method #1
    I assume the next line in your code after form.filter....
    is form.filteron=true? I don't know why you would get a
    primary key duplication, though.

    For method #2
    Here's how to fix the syntax...
    Don't use the '[]' brackets to enclose the VBA constants. Also, use
    quotes around your table name, not '[]' brackets. You also don't
    need to use the '()' to enclose the arguments.
    However, I don't think this will work for what you are trying to do here.
    (I could be wrong, though)

    Method #3 is possible, but probably requires more coding than it's worth
    to get to the solution you need.

  3. #3
    Join Date
    Jun 2003
    Provided Answers: 1
    If you are trying to find a record in a your source table based on what the user chooses from a dropdown, the combo-box wizard should guide you through this. Add a combo box and when the Wizard asks "How do you want to get your values?" choose option "Find a record in my form based on the value I selected in my combo box."

    Also, you could put your combo box in an outer form and put your data in a subform linked to it, but you would need to refresh your combo box if the underlying data changed.


Posting Permissions

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