Results 1 to 7 of 7
  1. #1
    Harold7 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2023
    Posts
    9

    Autofill problem

    I have a form that contains the teacher's name and info
    then a sub form inside that main form contains list of records of students under that teacher
    in front of each student has boxes that teacher's usually fill with [p] [p] [p] [p] which means the student was present during these periods
    I'm trying to make it easy for teachers to just click one button <fil all> the 4 boxes with the following vba code :

    Code:
    Dim subform As Form
    Dim ctl As ControlSet 
    
    subform = Me![AttendanceSubForm].Form
    
    For Each ctl In subform.Controls    
    
       If TypeOf ctl Is TextBox Then        
    
            If IsNull(ctl.Value) Or ctl.Value = "" Or ctl.Value = "A" Or ctl.Value = "E" Or ctl.Value = "A" Then   
             
                ctl.SetFocus            
    
                ctl.Value = "X"        
    
        End If    
    End If
    Next ctl
    
    Form look like this ..

    Click image for larger version. 

Name:	Screenshot 2023-11-15 043850.png 
Views:	14 
Size:	27.5 KB 
ID:	51037




    It does not auto fill all the students / records .. only the record that I click on
    Last edited by Harold7; 11-14-2023 at 07:42 PM.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Please post code between CODE tags to retain indentation and readability. The red highlight is not helpful.

    I don't allow empty string in fields so I would test for Null.

    You would have to loop through records. This is usually accomplished with a RecordsetClone object.

    Alternative is to run SQL UPDATE action.

    Are these textboxes bound to text field? Why would field have text "Late", "Excused", "Absent" if you want "X" input?

    Can provide db for analysis. Follow instructions at bottom of my post.
    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
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    So each day there is a record per teacher for all the students for all the classes? Do they select the date first?

  4. #4
    Harold7 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2023
    Posts
    9
    Quote Originally Posted by June7 View Post
    Please post code between CODE tags to retain indentation and readability. The red highlight is not helpful.

    I don't allow empty string in fields so I would test for Null.

    You would have to loop through records. This is usually accomplished with a RecordsetClone object.

    Alternative is to run SQL UPDATE action.

    Are these textboxes bound to text field? Why would field have text "Late", "Excused", "Absent" if you want "X" input?

    Can provide db for analysis. Follow instructions at bottom of my post.
    Thanks for the reply. I'll add the code tag but it seems to make the color of the code have same color as the post background and vanish.

    I looked up the object you mentioned but I'm not sure how to implement it in the code

    Regrding the fields "Excused, Absent..etc" sometimes these text boxes have these inputs by the teacher and I want to make them all "x" or "p" for present to auto fill them all

  5. #5
    Harold7 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2023
    Posts
    9
    Quote Originally Posted by Bulzie View Post
    So each day there is a record per teacher for all the students for all the classes? Do they select the date first?
    Exactly yes but they don't choose the date, it's set for the same day without their ability to modify it

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Something like:
    Code:
    With Me.RecordsetClone
    Do While Not .EOF
        'code to set values of relevant fields
        .MoveNext
    Loop
    End With
    Or an SQL UPDATE action like
    Code:
    CurrentDb.Execute "UPDATE tablename SET fieldname1 = 'X', fieldname2 = 'X', fieldname3 = 'X', fieldname4 = 'X' WHERE TeacherID = " & Me.TeacherID & " AND AttDate=Date()"
    Note: using CODE tags to format code. Doesn't seem to vanish.
    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.

  7. #7
    Harold7 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2023
    Posts
    9
    Quote Originally Posted by June7 View Post
    Something like:
    Code:
    With Me.RecordsetClone
    Do While Not .EOF
        'code to set values of relevant fields
        .MoveNext
    Loop
    End With
    Or an SQL UPDATE action like
    Code:
    CurrentDb.Execute "UPDATE tablename SET fieldname1 = 'X', fieldname2 = 'X', fieldname3 = 'X', fieldname4 = 'X' WHERE TeacherID = " & Me.TeacherID & " AND AttDate=Date()"
    Note: using CODE tags to format code. Doesn't seem to vanish.
    I chose your second suggestion and worked perfectly. Thanks for your help. I appreciate it.

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

Similar Threads

  1. Autofill
    By slimjen in forum Forms
    Replies: 3
    Last Post: 06-25-2019, 10:51 AM
  2. Replies: 1
    Last Post: 02-14-2015, 02:29 AM
  3. Autofill
    By Jpxfit in forum Access
    Replies: 4
    Last Post: 12-29-2014, 03:57 PM
  4. Autofill
    By evosheas in forum Access
    Replies: 4
    Last Post: 09-20-2011, 02:29 PM
  5. Autofill
    By kdcooper88 in forum Access
    Replies: 1
    Last Post: 09-18-2010, 05:52 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