Results 1 to 2 of 2
  1. #1
    usmcgrunt's Avatar
    usmcgrunt is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Location
    Just outside the gates of freedom
    Posts
    71

    Populate unbound listbox with VBA

    Ok, I have taken a swag a trying to populate a unbound listbox on a form with VBA. I'm here so it means that my swag didn't fair so well. My ultimate goal is to limit the records that show in a form based on a users access level that is stored in a hidden form.



    I have figured out how to filter the actual records displayed in the form in vba using a where stmt in the DoCmd.OpenForm code but I cannot figure out how to do the same for the listbox. If you are curious, I use the list box as a means to quickly select a record in the form rather that use the navigation buttons.

    In general terms I envision some vba code that goes something like this:

    If userAccess < X THEN
    display all records in the listbox.

    ELSEIF userAccess = X THEN
    display only records A,B,C in the list box

    ELSE
    display no records in the listbox

    My test code is below. As expected MS ACCESS popups a big error message that reads "HA HA HA, you have no idea what you are doing; keep trying." For one I have no idea which event to put this code in. ON top of that I have no idea if the code below is even close to being right.

    I have tried ON Open for the form: Compile error: expected: expression
    I have tried BEFORE UPDATE for the listbox: same error.

    Me.lbLessonList.RowSource = SELECT qryLessonCardData.LNumber, qryLessonCardData.LTitle _
    FROM qryLessonCardData _
    WHERE qryLessonCardData.Inactive = 0 _
    AND qryLessonCardData.LDivision = 1 _
    ORDER BY qryLessonCardData.LNumber;

    Help?
    Sean

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,524
    The row source property is a string:

    Me.lbLessonList.RowSource = "SELECT ..."
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 08-25-2010, 09:03 AM
  2. Unbound form example
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-24-2010, 12:25 AM
  3. Count and Sum of unbound fields?
    By C90RanMan in forum Forms
    Replies: 0
    Last Post: 07-29-2010, 01:17 PM
  4. Capture 2nd Value in an unbound Combo.
    By sesproul in forum Forms
    Replies: 5
    Last Post: 04-30-2010, 02:07 PM
  5. Unbound Text box in reports
    By Overdive in forum Reports
    Replies: 1
    Last Post: 02-17-2010, 09:52 AM

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