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

    Update records with checkboxes checked VBA

    Hi,



    I am working on writing a code to update records that has checkboxes checked.

    ================================================== ========================

    Desired Scenario:
    Assign a task to a manager with earliest assignment date who are 'Allowed to Auto Assign To'. (AllowAutoAssign checkbox field in the table)

    For example:
    Adam | AllowAutoAssign = True | Earliest Assignment = 5/1/00
    BoB | AllowAutoAssign = False | Earliest Assignment = 2/1/00
    Carl | Allow AutoAssign = True | Earliest Assignment = 3/1/00

    I click on a button to assign a task and the code would run and update Carl's record.

    ================================================== ========================

    I do not want to update BoB's even though he has the earliest assignment date because AllowAutoAssign is false.

    How do I write a such code??? Here is the code I have below that works but will not check for those checkboxes.


    Code:
    Private Sub btnAssign_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 qryAIA_AutoAssignListWorkloadTrackingLog")
                    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
                        Else
                        MyDB.Close
                        End If
                    End If
                    
                        DoCmd.GoToRecord , , acNewRec
                
                        For i = 0 To .ListCount
                                
                            If .ItemData(i) = stNextUser Then
                                .Value = stNextUser
                            End If
                        Next i
                        
                    Me.AMID.SetFocus
                    Me.AMID.Text = ""
                    Me.ACAID.SetFocus
                    frmSupport_AutoAssignWorkloadTrackingLog_Subform.Requery
                    
                    MsgBox "Task assigned successfully."
                Else
                    MsgBox "No task or manager to assign."
                    Me.AMID.SetFocus
                End If
            End With
    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,641
    You appear to be using a query, so presumably the criteria could be added there. You could also modify the SQL to use the TOP predicate, a WHERE clause to filter out the False records and an ORDER BY clause that sorted by date.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

    Thank you for your respond. I am not sure how to do this...

    Here is an image of my form with subform that I am using:


  4. #4
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    It is a difficult concept to implement. Having the pool or record set of Allowed is straight forward in that AllowAssign =-1. But matching that record manager's ID to a differing pool / records set of tasks (projects, whatever) is the hard part. In essence you must:
    a. pick 1 manager (i.e. maximum ID value or some suitable differentiating criteria)
    b. write manager ID into Project (assign) and then clear the AllowAssign to 0
    c. Count the record set of AllowAssign and if >0 then repeat A,B,C

    A. is a select query B. is an Update Query and then a second Update Query to clear the allow assign to 0 C. is either an Aggregate Query or a DCount of a select query. So it is not implemented purely in VBA - but rather some VBA which fires the various queries as logic dictates.

    Difficult to be more precise without digging into the actual structure of the data fields.

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

Similar Threads

  1. Automatically update a field when a box is checked
    By strangebiscuit in forum Access
    Replies: 11
    Last Post: 07-24-2014, 11:52 AM
  2. Update query for checkboxes
    By scoe in forum Queries
    Replies: 2
    Last Post: 06-20-2014, 07:12 AM
  3. Replies: 4
    Last Post: 06-03-2014, 10:30 AM
  4. Replies: 54
    Last Post: 07-17-2013, 03:01 PM
  5. Replies: 3
    Last Post: 11-07-2012, 08:44 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