Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    paramesium is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2013
    Posts
    20

    Update column in subform

    Hi All,

    I am working on a database project where I will Select a record on a subform

    Please see the picture attached.


    Click image for larger version. 

Name:	q2.JPG 
Views:	9 
Size:	9.9 KB 
ID:	14248
    I know that using DAO recordset, i can update the checkbox one by one, but it become way too long when I have thousands of record...

    May I know if there is a way to Select entire column of the subform?

    Please advice, thank you!

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    If you know the criteria of the subform's filtered recordset, you can create an SQL UPDATE query

    Does it take a long time to use a DAO recordset clone?

  3. #3
    paramesium is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2013
    Posts
    20
    Thank you for your reply, I actually did this, way too long...

    Code:
    With RstSearchSelected        
    .MoveFirst
            Do While Not .EOF
             .Edit
                 If !Selected <> False Then
                 !Selected = False
                 End If
             .Update
             .MoveNext
            Loop
        End With
    I have used the following:

    Code:
    Forms!frmFindChecklist!frmFindChecklist_Sub.Form.FilterOn = true
    the result in query no longer tally with what displayed in subform , and I am not sure how to use SQL on subform...

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Can you post the code where you ...

    Set RstSearchSelected = ?

  5. #5
    paramesium is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2013
    Posts
    20
    ok, this is the entire sub function

    Code:
    Private Sub cmdSelectAll_Click()
    
    
     'Parameters
        Dim db As DAO.Database
        Dim qdf As DAO.QueryDef
        Dim RstSearchSelected As DAO.Recordset
        
       
        Set db = CurrentDb()
        Set RstSearchSelected = frmFindChecklist_Sub.Form.Recordset
        
    
    
        With RstSearchSelected
    
    
            Do While Not .EOF
             .Edit
                 If !Selected <> True Then
                 !Selected = True
                 End If
             .Update
             .MoveNext
            Loop
    
    
        End With
        
    End Sub

    thank you

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    What is the name of the control that is bound to field "Selected"?

  7. #7
    paramesium is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2013
    Posts
    20
    The Selected field is actually a yes/no format of a table, which means I can update the each record of the "Selected" field directly, there are no other control that bound to it except the "cmdSelectAll" that I wanted code it to update the field for me when it is clicked.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Try this. I am not able to test it, but it should do the trick. I assume that the control name is "Selected"


    Code:
    Dim strFilterOld
    Dim strFilter As String
    If Forms!frmFindChecklist!frmFindChecklist_Sub.Form.FilterOn = True Then
        strFilterOld = Forms!frmFindChecklist!frmFindChecklist_Sub.Form.Filter
        strFilter = (strFilterOld & " AND ") & "[Selected] = -1"
        
    Else
        
        strFilterOld = ""
        strFilter = "([Selected] = -1)"
        
    End If
    
    Forms!frmFindChecklist!frmFindChecklist_Sub.Form.FilterOn = False
    Forms!frmFindChecklist!frmFindChecklist_Sub.Form.Filter = strFilter
    Forms!frmFindChecklist!frmFindChecklist_Sub.Form.FilterOn = True
    
        'Parameters
        Dim db As DAO.Database
        Dim qdf As DAO.QueryDef
        Dim RstSearchSelected As DAO.Recordset
        
       
        Set db = CurrentDb()
    '    Set RstSearchSelected = frmFindChecklist_Sub.Form.Recordset
        Set RstSearchSelected = frmFindChecklist_Sub.Form.RecordsetClone
        
            'Allow subform to be edited
           
    '    With Me![frmFindChecklist_Sub]
    '        .Form.AllowEdits = True
    '        .Form.AllowAdditions = True
    '        .Form.AllowDeletions = True
    '    End With
        
        With RstSearchSelected
            .MoveFirst
            
            !Selected = 0
            
    '        Do While Not .EOF
    '         .Edit
    '             If !Selected <> False Then
    '             !Selected = False
    '             End If
             .Update
             .MoveNext
            Loop
        End With
        
    If strFilterOld = "" Then
    Forms!frmFindChecklist!frmFindChecklist_Sub.Form.FilterOn = False
    Else
    Forms!frmFindChecklist!frmFindChecklist_Sub.Form.FilterOn = False
    Forms!frmFindChecklist!frmFindChecklist_Sub.Form.Filter = strFilterOld
    Forms!frmFindChecklist!frmFindChecklist_Sub.Form.FilterOn = True
    
    End If

  9. #9
    paramesium is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2013
    Posts
    20
    I have code it on my project, I have add one more .edit line, without that I couldnt compile, but when I added, it only clears the first record...

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by paramesium View Post
    I have code it on my project, I have add one more .edit line, without that I couldnt compile, but when I added, it only clears the first record...
    Are you trying to update the field to be True or False? Go ahead and post your revised code here.

  11. #11
    paramesium is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2013
    Posts
    20
    sorry that I didnt make myself clear, I am actually working on a search form,

    the search form will activate the filter on subform

    I want to make all the checkbox of the filtered data = true/false.

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Believe it or not, I got the part where you are using a filtered subform. That is why I am trying to see if there is a way to make DAO work.

    I understand you want to update a field on a table called "Selected". I assume there is a control on the subform named "Selected".

    Do you want to update all of the records in the subform or just certain records within the filtered subform?

    What value do you want to assign to the field in your table, the field named "Selected"?

  13. #13
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    This will update all of the records in the subform's filtered recordset. It will update the field "Selected" to True.

    Code:
        Dim RstSearchSelected As DAO.Recordset
        Set RstSearchSelected = Forms!frmFindChecklist!frmFindChecklist_Sub.Form.RecordsetClone
    
        With RstSearchSelected
        
            .MoveFirst
            
            While Not .EOF
            .Edit
            !Selected = -1
             .Update
             .MoveNext
            Wend
            
        End With

  14. #14
    paramesium is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2013
    Posts
    20
    strange, it is far more faster now!!

    I remember how I see those tick, ticking one by one in my last code ...

    do you mind explaining how is it work?

    Thank you so much!

  15. #15
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I don't know. There were several things that did not add up in the code you presented to me. I just tried to understand what you were trying to do and then use the least amount of code to get it done.

    One thing was to use the RecordsetClone. I do not remember seeing that in your original code.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 09-04-2013, 06:40 AM
  2. Replies: 1
    Last Post: 11-07-2012, 05:31 PM
  3. Update Column
    By access1 in forum Access
    Replies: 3
    Last Post: 10-22-2012, 08:24 AM
  4. Replies: 3
    Last Post: 09-13-2012, 11:14 AM
  5. Want to update a column A if column B = column C
    By AudiA4_20T in forum Queries
    Replies: 5
    Last Post: 08-08-2012, 02:42 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