Results 1 to 9 of 9
  1. #1
    hansdbase is offline Advanced Beginner
    Windows 11 Access 2021
    Join Date
    Nov 2022
    Posts
    33

    Requerying a list box with Sql server table data


    I don't have a persistent link to the sql server database. The form pulls data from the tables in sql server when it needs it. But I have a list box in the form that I want to occasionally requery when the user adds another record that will be populated in the sql server table. I have code that links the table, populates the new record, and then drops the link. After that is done, I want the listbox to requery to show all of the values including the new one just added for the table. I don't see a property field that will allow me to use a recordsource from a sql server database table that is unlinked. Do I have to have code create the connection, update the listbox from sql server, and then drop the link again? Or is there an easier way?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Requery listbox before dropping link?
    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
    hansdbase is offline Advanced Beginner
    Windows 11 Access 2021
    Join Date
    Nov 2022
    Posts
    33
    Quote Originally Posted by June7 View Post
    Requery listbox before dropping link?
    Thanks. Sometimes the best ideas are the most simple ones. I still have to programmatically load it the first time the form opens because I can't set the rowsource to a table that doesn't exist. Is there any other way around that? If not, no big deal. This was helpful.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Not that I know of for pulling data from SQLServer.
    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.

  5. #5
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    A simple pass-through query would do. If you are concerned about users looking at the Connect string property of the that you can set it in the load event of the form instead of having it saved with the query object itself.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    If users do not have access to navigation pane and can't open objects in design view, they could not see connection string property of PTQ.

    However, as far as I can tell, cannot edit data via PTQ so don't see how it could be useful as form RecordSource. No idea how to set PTQ connection property during load event of form.
    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.

  7. #7
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    I thought we were talking about populating a listbox now.
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Both? "I have code that links the table, populates the new record, and then drops the link. After that is done, I want the listbox to requery to show all of the values including the new one just added for the table."
    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.

  9. #9
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Yes, but the first part is done (the adding of the new record from an unbound form). But the OP now wants to populate the listbox when loading the unbound form and refresh it after inserting the new record. Which I believe can be easily done by using a pass-through query which can be saved or, if there are concerns, have its .SQL and .Connect properties set in the form's load event (using a QueryDef object).

    At least that is my understanding of the issue.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 9
    Last Post: 11-02-2019, 02:17 AM
  2. Export Data from Access 2003 Table to SQL Server 2012 Table.
    By Robeen in forum Import/Export Data
    Replies: 3
    Last Post: 02-26-2016, 02:07 PM
  3. Replies: 5
    Last Post: 02-10-2015, 04:37 PM
  4. Replies: 7
    Last Post: 08-20-2013, 06:03 AM
  5. Replies: 2
    Last Post: 04-05-2012, 08:39 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