Results 1 to 3 of 3
  1. #1
    Orabidoo is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2009
    Posts
    19

    Unhappy List box value to variable - invalid use of null?

    Hi everyone,

    An integer is read from a database into a listbox and I want to put this value into a variable or a text box, but I can't get it to work.

    Variable (int) = Listbox.Column(0) results in an error message (invalid use of null). Textbox = Listbox.Column(0) results in a blank text box.

    So...the list box always returns null, even though it displays the correct value. What to do?

  2. #2
    CraigDolphin is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Apr 2009
    Location
    Custer, WA, USA
    Posts
    125
    Some questions: Is this listbox multi-select or not?
    Have you actually selected the item in the listbox?

    if it is not multiselect, and you have actually slected an item in the list box, something like

    Variable = Me.ListBox1.SelectedItem.Value
    should work.
    If you haven't selected an item, you need to handle the possibility of a null. Integers cannot accept nulls.
    So Variable = Nz(Me.ListBox1.SelectedItem.Value,0)
    would substitute the value 0 if it finds a null

  3. #3
    Orabidoo is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2009
    Posts
    19
    Thanks! However the solution was very simple. Specifying the row as well did the trick: Column(0, 0). This is the second time I follow an example and it turns out to be wrong. Really makes you pull your hair...

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

Similar Threads

  1. List box to populate other list boxes
    By Nathan in forum Forms
    Replies: 0
    Last Post: 03-03-2009, 07:22 PM
  2. Variable Criteria
    By JamesLens in forum Queries
    Replies: 0
    Last Post: 01-02-2009, 04:55 PM
  3. Variable question
    By synapse5150 in forum Programming
    Replies: 1
    Last Post: 07-09-2008, 08:17 AM
  4. Replies: 0
    Last Post: 11-17-2006, 09:38 AM
  5. Invalid Operation
    By ScottG in forum Forms
    Replies: 0
    Last Post: 11-14-2006, 02:05 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