Results 1 to 4 of 4
  1. #1
    SansPeur is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    9

    Getting listbox to clear when new record selected

    Have not been able to figure this out and would greatly appreciate some assistance...

    Here is my database (tables and forms design):

    Database design (portion)
    tblEmployee (main table)
    EmployeeID (autonumber, PK)
    LastName (text)
    FirstName (text)



    tblIALvl (data table)
    IALvlID (autonumber, PK)
    IALvl (text)

    tblEmployeeIALvlJunction (M-M junction between tblEmployee and tblIALvl)
    EmployeeIALvlID (autonumber, PK)
    EmployeeID (long integer, FK from tblEmployee)
    IALvlID (long integer, FK from tblIALvl)


    frmEmployee (Main Form)
    EmployeeID (bound to tblEmployee.EmployeeID) textbox (PK)


    frmEmployeeIALvlJunction (subform of frmEmployee)

    EmployeeID (bound to tblEmployeeIALvlJunction.EmployeeID) textbox (FK from tblEmployee)
    EmployeeID Default Value =[Forms]![frmEmployeeNew]![EmployeeID]

    Current IA Lvl (unbound) Listbox is populated using CurrentIALvlQuery
    SELECT tblIALvl.IALvl, tblIALvl.IALvlID, tblEmployeeIALvlJunction.EmployeeID
    FROM tblIALvl INNER JOIN (tblEmployee INNER JOIN tblEmployeeIALvlJunction ON tblEmployee.EmployeeID = tblEmployeeIALvlJunction.EmployeeID) ON
    tblIALvl.IALvlID = tblEmployeeIALvlJunction.IALvlID
    WHERE (((tblEmployeeIALvlJunction.EmployeeID) = [Forms]![frmEmployeeNew]![EmployeeID]));

    Process flow:
    The main form is used to input new employee data. When opened, it begins at a “New” record (EmployeeID is set to “New”). When beginning to enter the last name, EmployeeID is set by autonumber.

    The frmEmployeeIALvlJunction sub-form uses frmEmployee.EmployeeID to set EmployeeID via Default Value control. I use a combobox (IALvl bound to Control source IALvlID, and data selected by a query: SELECT tblIALvl.IALvlID, tblIALvl.IALvl) to select the IA Lvl. Then use a Save Record button to save the data. When this happens, the listbox CurrentIALvl returns the information derived from the query CurrentIALvlQuery (above). When I click the “Add new record” button on the main form, EmployeeID is then set to “New”, and EmployeeID on the subform is not set until new data is input into the main form (then set to the value in EmployeeID from the main form).

    Problem:
    The list box (in the sub form), however, still shows the data from the previous record. What is causing this, and how can I make it so that the listbox also clears the data?

    Thanks very much in advance!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Requery the listbox. Is the 'add new record button' a command button or the built-in button from the navigation bar?

    Trick is figuring out the correct event to put the code in. Try the Current event of the subform. Could be simply: Me.listboxname.Requery
    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
    SansPeur is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    9
    June7, thanks for the reply. The 'add new record button' is a command button. I will try the Me.listbox.Requery code.

  4. #4
    SansPeur is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    9
    June7, that worked! Thanks!

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

Similar Threads

  1. Clear selected value in combo box
    By bbrazeau in forum Programming
    Replies: 6
    Last Post: 08-05-2014, 12:38 AM
  2. Replies: 3
    Last Post: 11-29-2011, 12:54 AM
  3. Deleting multiple records selected in a Listbox
    By ankitmehtta in forum Access
    Replies: 4
    Last Post: 11-08-2011, 01:20 PM
  4. Replies: 3
    Last Post: 02-01-2011, 09:47 AM
  5. Selected items in listbox
    By tomodachi in forum Access
    Replies: 1
    Last Post: 09-09-2010, 01:14 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