Results 1 to 5 of 5
  1. #1
    natilton is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    7

    Update first null record in a Scheduling table with Current Record's ID number in "Main" table


    Hello,

    I have a "main" table (tblMonCE) with information about each person recruited for a clinical trial. I created another table (tblEvalProg) with the following structure, so that I could automatically fill up evaluation date-slots with ID numbers after each person enrolls.
    SlotNum FechaEval InfID
    1 2-Mar
    2 2-Mar
    3 2-Mar
    4 3-Mar
    5 3-Mar
    6 3-Mar

    It looks like my query to select the first null record is working

    qry1stAvailCE
    Code:
    SELECT TOP 1 tblEvalProg.SlotNum, tblEvalProg.FechaEval, tblEvalProg.InfID
    FROM tblEvalProg
    WHERE (((tblEvalProg.InfID) Is Null));
    However, when I call QueryAvail to update InfID in the selected record in an AfterUpdate procedure, it updates with caseID in the last record in tblMonCE instead of the current record.

    QueryAvail
    Code:
    UPDATE qry1stAvailCE, tblMonCE SET qry1stAvailCE.InfID = [tblMonCE].[caseID];
    The VBA AfterUpdate code that calls QueryAvail
    Code:
    Private Sub Enroll_Date_AfterUpdate()
     
    Dim strSQL As String
    strSQL = "QueryAvail"
    
        If Not IsNull(Enroll_Date) Then
            CurrentDb.Execute strSQL
        End If
    
    End Sub
    Am I missing something simple? I apologize for any ham-handedness here, and thanks in advance for any help you might be able to provide. I am seriously stuck.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Never seen anything like this. Maybe apply SORT criteria in qry1stAvailCE to make sure the earliest record really is the TOP record when the UPDATE runs.
    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
    natilton is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    7
    Quote Originally Posted by June7 View Post
    Never seen anything like this. Maybe apply SORT criteria in qry1stAvailCE to make sure the earliest record really is the TOP record when the UPDATE runs.
    Hello, and thanks for your reply. I don't think qry1stAvailCE is the problem here, because when I run it by itself, it always selects the record with the lowest SlotNum to have a null InfID. The problem is that when I run the Update query from my form (after an update to the control for the field Enroll_Date), the selection from qry1stAvail is updated with the caseID from the last record in tblMonCE instead of the form's current record.

    I'm fairly new to all this, but in my UPDATE statement, is there some identifier I'm supposed to use to indicate that I want to set the selection equal to the caseID from the form's current record?

    Thanks

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Sorry, missed that in the original post.

    Then refer to the form instead of the table.

    UPDATE qry1stAvailCE, tblMonCE SET qry1stAvailCE.InfID = [Forms].[formname].[caseID];
    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
    natilton is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    7
    Quote Originally Posted by natilton View Post
    Hello, and thanks for your reply. I don't think qry1stAvailCE is the problem here, because when I run it by itself, it always selects the record with the lowest SlotNum to have a null InfID. The problem is that when I run the Update query from my form (after an update to the control for the field Enroll_Date), the selection from qry1stAvail is updated with the caseID from the last record in tblMonCE instead of the form's current record.

    I'm fairly new to all this, but in my UPDATE statement, is there some identifier I'm supposed to use to indicate that I want to set the selection equal to the caseID from the form's current record?

    Thanks
    That did the trick, thanks so much.

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

Similar Threads

  1. Replies: 5
    Last Post: 11-19-2014, 08:47 AM
  2. Replies: 8
    Last Post: 11-26-2013, 12:21 PM
  3. Replies: 10
    Last Post: 03-15-2013, 05:46 AM
  4. Replies: 3
    Last Post: 03-14-2012, 12:33 PM
  5. Creating "Edit Record" link in table column
    By joshearl in forum Forms
    Replies: 1
    Last Post: 12-25-2009, 11:17 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