Results 1 to 12 of 12
  1. #1
    IamKJVonly is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2018
    Posts
    41

    trouble using a list box: when I click on a row it does not carry the row ID number to the next form

    I have made a list box using the listbox wizard


    It seems to work until I click on a row in the listbox
    I have a macro for “On click” which opens another form
    My problem is that it will open the form ok except my row ID is always 0
    The row ID in the list box that I clicked on shows the correct row ID In fact I get at times popup box asking for that parameter which I enter but the form still opens with the row ID still 0

    What am I doing wrong??

    I have selected remember this value for later use “rowID”

    Any help will be greatly apricated
    DAVE

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Can you show us the Row Source Property setting for the listbox.
    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
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    the macro should run in AFTER UPDATE event.
    check the listbox bound column, is it on the ID column?

  4. #4
    IamKJVonly is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2018
    Posts
    41
    It is "SELECT [ContactTable].[ContactID], [ContactTable].[ContactName], [ContactTable].[DateLastUsed] FROM ContactTable ORDER BY [ContactName];"

    Note: ContactID is my row id
    Hope this helps
    Dave

  5. #5
    IamKJVonly is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2018
    Posts
    41
    Note the listbox bound column says "1" which is the first column that show in my list I have the row Id as the first column and it is not hidden
    Hope this helps
    Dave

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Can you post a copy of the db with just a few fictitious records ti illustrate the problem
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    IamKJVonly is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2018
    Posts
    41
    I'm sorry guys but I'm out of time I hope to get back to you later today
    Thanks for trying I'm just out of time.

    Dave

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    You have to specify the ID in the WHERE clause of the open form statement?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    IamKJVonly is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2018
    Posts
    41
    After struggling all last evening and this morning here is what I have come up with.

    I can't seem to follow instructions very well as I can't figure out how to attach a file so that option is out.

    However, I ran across the following statement:
    "The parameter has to reference the listbox control. Instead of [enter number here] in must be like [Forms!formname!listboxname]."

    So I changed my where statement form "="Contact_ID=" & [Contact_ID]" to the following:
    ="Contact_ID=" & [Forms]![frm_AllContacts]!
    [List0]![Contact_ID]

    =" [Forms]![frm_AllContacts]!
    [List0]![Contact_ID]=" & [Forms]![frm_AllContacts]!
    [List0]![Contact_ID]

    and I get a "type mismatch" error on both attempts

    Note: I'm getting the following error message on "="Contact_ID=" & [Contact_ID]" when I run it:

    The object doesn’t contain the Automation object “[Contact_ID.”
    You tried to run a Visual Basic procedure to set a property or method for an object. However the component doesn’t make the propery or method available for Automation operation.
    Check the component’s documentation for information on the properties and methods it makes available for Automation operations

    I'm hoping this may be the information someone needs to help me as I am out of ideas as to what to do.
    Dave

  10. #10
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by IamKJVonly View Post
    I can't seem to follow instructions very well as I can't figure out how to attach a file so that option is out.
    Detailed instructions to attach a file to a reply":
    1. Make a copy of your dB
    2. Open the dB
    3. Do a "Compact and Repair"
    4. Close the dB
    5. Compress (Zip) the dB. If you don't have Win Zip or a program like it, right click on the copy of the dB and select "Send To". In the next dialog box, select "Compressed (zipped) folder.
    6. In your thread, create a reply.
    7. Below the reply box, click in "Go Advanced"
    8. Scroll down until you see "Manage Attachments". Follow the prompts.

    --------------------------------------------------------------
    So there are a couple of things to look at.

    In the list box, you have set the Row Source to:
    Code:
    SELECT [ContactTable].[ContactID], [ContactTable].[ContactName], [ContactTable].[DateLastUsed] 
    FROM ContactTable 
    ORDER BY [ContactName];
    There are 3 COLUMNS in the list box.
    First column is [ContactTable].[ContactID]
    Second column is [ContactTable].[ContactName] (more on this column later)
    Third column is [ContactTable].[DateLastUsed]

    Most controls have a default PROPERTY. The default PROPERTY for a List/Combo box is the Value property. (Not the same as a control Default Value)
    Now, in the list box, if you set the BOUND COLUMN to 1, and you refer to the list box like
    Code:
     Msgbox Me.Listbox0
    the value that is returned is the value in the row selected of the first column (in this case the ContactID column). Note that the BOUND COLUMN property is one (1) based.

    If you set the BOUND COLUMN to 2, and run the code above, the value that is returned is the value in the row selected of the second column (in this case the ContactName column)
    If you set the BOUND COLUMN to 3, and run the code above, the value that is returned is the value in the row selected of the thirdcolumn (in this case the DateLastUsed column)

    This means that the combo box doesn't know from Sxxt from shinola about field names.
    Which is why you get the error
    Quote Originally Posted by IamKJVonly View Post
    Note: I'm getting the following error message on "="Contact_ID=" & [Contact_ID]" when I run it:

    The object doesn’t contain the Automation object “[Contact_ID.”
    You tried to run a Visual Basic procedure to set a property or method for an object. However the component doesn’t make the propery or method available for Automation operation.
    So you cannot have a WHERE string/clause like
    "Contact_ID=" & [Forms]![frm_AllContacts]!
    [List0]![Contact_ID]
    You MUST use the Column property.
    "Contact_ID=" & [Forms]![frm_AllContacts]!
    [List0].Column(0)
    Note that the column property is zero (0) based.

    On the "Format" tab of Property Sheet of the combo box, is the "Column Count". It is also one (1) based.
    If you DO NOT want to see the "ContactID" in the list box set the "Column Widths" property to zero to hide the column [Contact_ID].


    I would suggest that you set both the BOUND COLUMN property to 0 (zero) and the Column Widths property to 0 (zero).

    -----------------------------------------------------------------------------

    OK, its later. I recomment that you split the "ContactName" field into "ContactFirstName" and "ContactLastName". If you need to have the full name, you can always concatenate them. Plus, you can sort the names by Last Name,First Name.
    Code:
    SELECT ContactTable.ContactID, [ContactTable].[ContactLastName] & ", " & [ContactTable].[ContactFirstName] AS Fullname, ContactTable.DateLastUsed
    FROM ContactTable
    ORDER BY [ContactTable].[ContactLastName] & ", " & [ContactTable].[ContactFirstName];



    Maybe you would post the code for the List box Click event?

  11. #11
    IamKJVonly is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2018
    Posts
    41
    Steve
    you are a life saver God bless you because the code "Contact_ID=" & [Forms]![frm_AllContacts]!

    [List0].
    Column(0) works and I even understand the code.

    Thank you for taking the time to work with me.
    That is why I like this forum . It's people like you that keep people like me going.
    Happy days are here again.
    Dave


    I can't fine "Thread tools" to mark mark this thread solved sorry
    Dave

    Last edited by IamKJVonly; 02-26-2022 at 01:25 PM.

  12. #12
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Happy to help. Hope I wasn't too long winded, but I wanted to be sure I explained it good/well/best as i could.

    The "Thread tools" is just above the first post, oh the right hand side (in the green bar). I'll mark it solved for you.

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

Similar Threads

  1. Replies: 5
    Last Post: 08-06-2018, 05:31 PM
  2. Replies: 7
    Last Post: 02-02-2018, 12:42 PM
  3. Replies: 8
    Last Post: 12-13-2017, 10:38 AM
  4. Replies: 0
    Last Post: 01-03-2011, 03:38 PM
  5. Replies: 13
    Last Post: 06-01-2010, 09:55 PM

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