Results 1 to 6 of 6
  1. #1
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56

    clear rowsource on Form Unload

    I am trying to clear the Row Source of a list on my form as the access file closes. I cannot get it to work. What am I doing wrong?



    Code:
    Public Sub Form_Unload()
      List17.RowSourceType = ""
      List17.RowSource = ""
      List17.Requery
    End Sub

  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,652
    What happens? You'd have to save the form. I'd be more likely to have the first 2 lines in the open event of the form, if your goal is that it be blank when the form opens.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56
    So when I open my access file, an error occurs because the list rowsource points to a table that does not yet exist. This table gets created by a load file button via transferspeadsheet. After the table is created the list becomes populated. At the end of my process, I delete the table because a new file will be loaded on next run. So each time I either open/close the database file I need to clear out the rowsource? What is the best way to do this?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Simplest is probably no code, just delete the row source in design view and save the form. That way it has no source when it opens. Then you can set it at the appropriate time. As a rule, I'd empty/repopulate a table rather than delete/recreate.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56
    Thanks. However I cannot empty and repopulate as each time a run the process, a different file with a different number of fields is loaded.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I understand. Try that code in the open event.
    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. Clear form
    By wickedjc in forum Access
    Replies: 2
    Last Post: 02-02-2016, 06:18 PM
  2. Unload called when opening a form?
    By Kirtap in forum Programming
    Replies: 6
    Last Post: 12-11-2013, 06:23 AM
  3. Replies: 5
    Last Post: 06-04-2013, 10:12 AM
  4. Replies: 6
    Last Post: 05-07-2012, 05:41 PM
  5. Replies: 0
    Last Post: 03-11-2012, 09:19 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