Results 1 to 11 of 11
  1. #1
    graccess is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    78

    Question populate a text box after a combo box selection is made

    Not sure what's going wrong with this code. Trying to simply populate a text field after a selection is made to a corresponding combo box. getting a run-time error 2471.




    Private Sub cboticker_AfterUpdate()
    Me.txtCompany.ControlSource = DLookup("Company", "Companytable", "cboticker = " & Nz([Ticker], 0))

    Me.txtCompany.Requery
    end sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    What is the exact error message?

    Are you trying to save Company name to record?

    The WHERE CONDITION expression is backwards, assuming cboTicker is the combobox name.

    Is Ticker a text field?

    "Ticker='" & Me.cboTicker & "'"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    graccess is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    78
    Run-time error '2471':
    The expression you entered as a query parameter produced this error: 'EE'

    'EE' was the sample I selected in the ticker box. I'm trying to produce the company name that exists in the record with a ticker field value of 'EE' - the cboTicker is the combo box name that is independent here. Ticker is a text field. The way I thought the code would read is, if cboticker matches the ticker field in my table, produce the record and populate the company field text box. I plan on populating several fields after the cboticker cmbo box is changed but thought I'd test it on one for now. Good thing for that.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    An easier way is to include the company in a column of the combobox. Then reference the column to pull the company. Can be an expression in textbox. Column index begins with 0 so if Company is in column 2 the index is 1.

    =[cboTicker].[Column](1)

    Do you need to save Company to record?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    graccess is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    78
    When you say include the company in a column of the combo box, where would i input that, as a control source for my company text box? I tried inputting in the code for my afterupdate combo box (cboticker) and set the company text field equal to =[cboTicker].[Column](1) --- apparently not correct?

    Yes, I will also need the ability to save this a s a record in addition to retrieving the record. However, I only want one record for each company so if i were to re-save the record I don't want to end up with a new ID generated every time, unless of course it's a new ticker altogether, I would rather it just copy over what's already there. Make sense?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    graccess is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    78
    Quote Originally Posted by June7 View Post

    thanks, this was helpful. however, I may have missed how the secondary text box was reflecting the bound column, especially when that text box was unbound. Also, if I had multiple boxes that needed filled off the combox query, how would I set that?
    thanks again.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    see post 4
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    graccess is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    78
    works beautifully. many thanks! one new problem however, when I expand this to include an expression which places a predefined value for additional fields that include a different combo box(as opposed to the text box I had) and a date field they do not populate those results. I checked the columns and I believe I'm referencing the correct ones. any ideas?

    Private Sub cboticker_AfterUpdate()
    Me.txtCompany = [cboTicker].[Column](1)
    Me.cboSector = [cboTicker].[Column](2)
    Me.cboSubIndustry = [cboTicker].[Column](3)
    Lastupdate = [cboTicker].[Column](4)
    Me.cbxFlag = [cboTicker].[Column](5)

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    All these controls are bound to fields? I still don't understand why you are saving this data. Users are allowed to change the data in any of these controls?

    Neither of the comboboxes show the data? Probably has something to do with combobox properties.

    Why does Lastupdate not have the Me. qualifier?

    Afraid I don't know why the controls are not populated. Would have to examine the form.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    graccess is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    78
    Quote Originally Posted by June7 View Post
    All these controls are bound to fields? I still don't understand why you are saving this data. Users are allowed to change the data in any of these controls?

    Neither of the comboboxes show the data? Probably has something to do with combobox properties.

    Why does Lastupdate not have the Me. qualifier?

    Afraid I don't know why the controls are not populated. Would have to examine the form.

    All the controls are bound to fields, yes. I'm saving the data because I'd like to make the input and retrieval easier in the future by having a uniform search of the ticker. It's possibly I could use a web interface to retrieve this information each time but i thought I could be saving myself time later on by having these fields already populated. I plan on adding hundreds of notes to each unique company over time and I'll be the only data entry person for now so I plan on adding and changing data with a form. I suppose I could just add tickers and company info directly to the table and go from there, but since I plan on having this operation with the notes(viewing and saving an edited note) I wanted to learn this functionality.

    I dropped the me. qualifier because it was giving me errors on the date field and I wanted to focus on resolving the above issue first.
    I'm sure I did something, or didn't do something with the fields that I'm overlooking. I need to go over it more carefully, otherwise it all looks like the text box which is the only field working.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 07-20-2015, 10:55 AM
  2. Replies: 2
    Last Post: 09-10-2013, 09:10 AM
  3. Replies: 3
    Last Post: 07-03-2013, 10:38 AM
  4. Replies: 3
    Last Post: 12-11-2012, 09:12 AM
  5. Replies: 0
    Last Post: 12-02-2010, 11:59 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums