Results 1 to 8 of 8
  1. #1
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93

    Recordset to update date/time Issue

    Hello Accessers,



    I am trying to have the code perform these things but unable to do so. While the code would still work, it will not move to the next user with either no date or the earliest date.

    Goal:
    -Go through the query record by record according to the date/time field
    -Find the record with no date or earliest date (in that order)
    -change its date to today's date

    Code:
    Code:
    Private Sub Command56_Click()    Dim i As Long
              
            With Screen.ActiveForm.[AMID]
                Dim LResponse As Integer
                
                LResponse = MsgBox("Do you wish to auto-assign to an Accreditation Manager?", vbYesNo, "Continue")
                
                If LResponse = vbYes Then
                    Dim stNextUser As String
                    Dim MyDB As Object
                    Dim RS As Recordset
                    Set MyDB = CurrentDb
                    
                    stNextUser = ""
                
                    Set RS = MyDB.OpenRecordset("select * from qryTEST")
                    lngRSCount = RS.RecordCount
                    If lngRSCount <> 0 Then
                        RS.MoveFirst
                        
                        stNextUser = Trim(RS.Fields("Initials").Value)
                        
                        RS.Edit
                        RS.Fields("LastAssignment").Value = Now()
                        RS.Update
                        RS.Close
                        MyDB.Close
                        
                        DoCmd.GoToRecord , , acNewRec
                
                        For i = 0 To .ListCount
                                
                            If .ItemData(i) = stNextUser Then
                                .Value = stNextUser
                            End If
                        Next i
                    End If
                Else
                   Me.AMID.SetFocus
                End If
            End With
    End Sub
    Any help would be appreciated.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Please show sql for qryTest.

    Also, t looks like you're closing the database in the middle of processing.
    MyDB.Close

  3. #3
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    Hi orange,

    Here's the sql for qryTest:
    Code:
    SELECT tblAIA_STAFFList.ID, tblAIA_STAFFList.LastAssignment, tblAIA_STAFFList.AllowAutoAssign, tblAIA_STAFFList.InitialsFROM tblAIA_STAFFList
    WHERE (((tblAIA_STAFFList.AllowAutoAssign)=Yes));
    As for MyDB.Close, it is odd because it does work on the previous database before I created a new split database and migrated everything there and I did major tweaking to make the tables, forms, reports and queries to work. This is one more thing I am working on migrating at the moment.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    You are asking about auto-assign. Do you process a list, or do you intend to go through a list one by one?
    Do you have a group of managers that you want to update as a group?
    Can you describe in plain English exactly WHAT you want to do?

  5. #5
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    Plain English:

    I want to auto-assign a task to a manager from a list of managers.

    -If the manager is not assigned, assign the task to that manager.
    -If all of the managers are assigned, assign the task to the manager with the earliest date.

    Hope this is simple enough.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    What exactly is the manager with the earliest date?

    So is it one task to be assigned? Or a list of Tasks to be assigned to various managers?

    If a list of tasks, and a list of managers
    -sort the manager list in whatever order you need (whatever earliest date means)
    -assign Task1 to first manager
    -assign Task2 to second manager
    -continue loop to assign task to next manager until all tasks have been assigned.

    if 1 task and a list of managers, find first manager (on some basis) that is currently unassigned, then
    -assign the task to that manager

  7. #7
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    One task per manager.

    -----------------
    Manager with the earliest date means:

    Scenario 1
    Manager A | March 2014
    Manager B | February 2014
    Manager C | July 2014

    The task to be assigned will be assigned to Manager B.


    Scenario 2
    Manager A |
    Manager B | August 2014
    Manager C | January 2014

    The task to be assigned will be assigned to Manager A.
    ---------------------

    The code would need to be able to perform both scenarios at any time.

    Hope this helps picture the intended operation of the code.
    Last edited by excellenthelp; 12-19-2014 at 09:50 AM. Reason: Added more info.

  8. #8
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    Ah- I found the culprit. It was because the date field was not sorted when it needs to be ascending in the 'Assignment' table. It works now.

    However, I would like to update the active form's textbox with today's date while assigning. It would update the Manager textbox but not the date in the 'Task' table. How do I update that?

    The current code that works is below:
    Code:
    Private Sub Command56_Click()    Dim i As Long
              
            With Screen.ActiveForm.[AMID]
                Dim LResponse As Integer
                
                LResponse = MsgBox("Do you wish to auto-assign to an Accreditation Manager?", vbYesNo, "Continue")
                
                If LResponse = vbYes Then
                    Dim stNextUser As String
                    Dim MyDB As Object
                    Dim RS As Recordset
                    Set MyDB = DBEngine.Workspaces(0).Databases(0)
                    
                    stNextUser = ""
                    
                    Set RS = MyDB.OpenRecordset("select * from qryTEST")
                    lngRSCount = RS.RecordCount
                    
                    If lngRSCount <> 0 Then
                        With RS
                            .MoveFirst
                            stNextUser = Trim(RS.Fields("ID").Value)
                            .Edit
                            .Fields("LastAssignment").Value = Now()
                            .Update
                            .Close
                        End With
                        MyDB.Close
                    End If
                    
                        DoCmd.GoToRecord , , acNewRec
                
                        For i = 0 To .ListCount
                                
                            If .ItemData(i) = stNextUser Then
                                .Value = stNextUser
                            End If
                        Next i
                Else
                   Me.AMID.SetFocus
                End If
            End With
    End Sub

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

Similar Threads

  1. Date/Time Issue
    By dsaxena15 in forum Access
    Replies: 2
    Last Post: 02-09-2013, 02:29 PM
  2. ACCESS DATE/TIME Issue! Thanks!
    By keledidi in forum Access
    Replies: 6
    Last Post: 08-07-2012, 09:55 PM
  3. Date/Time Issue
    By bdhFS in forum Access
    Replies: 2
    Last Post: 08-02-2012, 04:22 PM
  4. Log time and date users update records
    By Richie27 in forum Programming
    Replies: 6
    Last Post: 06-13-2012, 09:28 AM
  5. Date/Time Search Midnight Issue
    By Coffee in forum Queries
    Replies: 5
    Last Post: 07-26-2011, 01:54 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