Results 1 to 6 of 6
  1. #1
    ringram is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2014
    Posts
    16

    error when selecting first item in combo box with column head

    I have an combo box with column head on.
    there are three columns in the combo box
    column 0 id (hidden)
    Column 1 description
    column 2 type

    After selecting an item from the list box I execute code to get the quantity available from a table in the database
    the code is below.
    if I select any other item but the first one in the combo box the code works just fine.
    if I turn column head off the code works fine.
    If I select the first item in the combo box with column head on I get an error. Type mismatch on the line in red.
    Debugging the code it looks like when I try to select the first item in the combo list instead of returning the value of the id for that item it is returning the column head of "ID"

    Code:
    Private Sub iDescription_AfterUpdate()     Dim selected, selectedid As Integer
         selected = Me.iDescription.ListIndex 
         selectedid = Me.iDescription.Column(0, selected)
         Me.type = Me.iDescription.Column(2, selected)
         me.qtyavailable = DLookup("quanity", "inventory", "ID =" & selectedid)
    Me.iprice.SetFocus
    End Sub
    I am using Access 2007.



    any Ideas?
    Last edited by ringram; 10-15-2014 at 01:07 PM. Reason: solved

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Just a guess, but try:
    Private Sub iDescription_AfterUpdate()
    Dim selected, selectedid As Integer
    selected = Me.iDescription.ListIndex + 1
    selectedid = Me.iDescription.Column(0, selected)
    Me.type = Me.iDescription.Column(2, selected)
    me.qtyavailable = DLookup("quanity", "inventory", "ID =" & selectedid)
    Me.iprice.SetFocus
    End Su
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why do you need to reference combobox row? Once item is selected, the other column values for that row are available. Just reference the value of the combobox and column index.

    Me.type = Me.iDescription.Column(2)
    Me.qtyavailable = DLookup("quanity", "inventory", "ID=" & Me.iDescription

    Do you know that quantity is misspelled?
    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.

  4. #4
    ringram is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2014
    Posts
    16
    Thanks I actually had just given this a try and it did work.
    It does not make any sense but it does.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    It makes sense because selecting item doesn't just select the value of the column, it selects the row.
    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.

  6. #6
    ringram is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2014
    Posts
    16
    yes I have to go in and fix the spelling of Quantity. I noticed that just after posting this.
    I am self taught Access and vba. I found that way of referencing the combo box and used it. thanks for showing me a better way.

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

Similar Threads

  1. listbox column head format backcolor
    By masoud_sedighy in forum Programming
    Replies: 3
    Last Post: 07-31-2013, 07:44 PM
  2. Replies: 1
    Last Post: 07-12-2012, 08:39 AM
  3. Selecting a combobox item with VBA
    By tylerg11 in forum Forms
    Replies: 6
    Last Post: 04-19-2012, 12:30 PM
  4. Get column head name from list box?
    By joelmeaders in forum Programming
    Replies: 3
    Last Post: 01-31-2012, 11:23 AM
  5. sales DB selecting column and column range
    By pher77 in forum Queries
    Replies: 3
    Last Post: 06-11-2011, 04:04 PM

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