Results 1 to 4 of 4
  1. #1
    TotalNovice is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    7

    Changing RowSource when a form opens?

    Last problem for the day, before I go home and remind myself that love still exists in the world!



    I have a form that I'm trying to make multipurpose. It's the form I was working on here. That one wrote to the "tblOwnersmm" table. I want another to write to the "tblResourcesmm" table. Instead of duplicating all the objects, I figured I'd just throw some variables in and reuse what I had. Everything works EXCEPT for one thing... When the form opens, it's showing the previous rowsource. So, if I reopen the same thing (owners or resources) it looks perfect. But if you open one then the other, it shows you the previous list.

    I have queries made for both of these. Here's my code, which I've tried on Form_Open and Form_Load

    Code:
    Select Case TempVars!strFormTable
        Case "tblOwnersmm"
            Me.RecordSource = "tblOwnersmm"
            Me.lbSource.RowSource = "qryOwnerUnassigned"
            Me.lbDestination.RowSource = "qryOwnerAssigned"
            'MsgBox "owner"
        Case "tblResourcesmm"
            Me.RecordSource = "tblResourcesmm"
            Me.lbSource.RowSource = "qryResourceUnassigned"
            Me.lbDestination.RowSource = "qryResourceAssigned"
            'MsgBox "resource"
    End Select
    Me.Requery
    Me.lbSource.Requery
    Me.lbDestination.Requery
    Is that enough to see what I've missed? It's making the updates to rowsource and recordsource, but it doesn't seem to take effect until the NEXT time the form opens.

    Thanks in advance!

  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,521
    I don't use TempVars, but is it possible TempVars!strFormTable isn't being set in time? The code looks okay offhand, and in my experience the requery lines shouldn't be needed.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    TotalNovice is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    7
    Quote Originally Posted by pbaldy View Post
    I don't use TempVars, but is it possible TempVars!strFormTable isn't being set in time? The code looks okay offhand, and in my experience the requery lines shouldn't be needed.
    You nailed it. As I was updating my code, I noticed that the form was being called BEFORE setting the TempVar. A silly mistake at the end of a 10 hour day.

    Thanks for the tip about requery too. I added those when it wasn't updating as expected, but will be sure to remove them. Anything to make it a bit more responsive for my users!

  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,521
    Excellent! We've all had those brain cramps. The requery lines aren't hurting anything, but could create a slight extra lag.
    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 rowsource on Form Unload
    By gammaman in forum Modules
    Replies: 5
    Last Post: 07-13-2016, 02:06 PM
  2. Replies: 21
    Last Post: 08-05-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: 7
    Last Post: 01-29-2012, 07:44 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