Page 3 of 3 FirstFirst 123
Results 31 to 40 of 40
  1. #31
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654

    You could try something along these lines. Undo changes to previous records or force completion of new records.

    In the required fields of the subform place V8 in the tag property.

    Code goes in the subform's before update event

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    
        Cancel = IsFrmInvalid(Me, "OrderID")
    
    
    End Sub
    Code:
    Function IsFrmInvalid(frm As Form, PKeyName As String) As Boolean
    
    
        Dim ctl As Control
           
        For Each ctl In frm.Controls
    
    
            If ctl.Tag = "V8" Then
            
                If IsNull(ctl) Then
                
                    If Not frm.NewRecord Then
                
                        IsFrmInvalid = False
                     
                        frm.Undo
                
                        MsgBox "Changes to " & PKeyName & " " & ctl.Parent(PKeyName) & " have been undone"
                        
                    Else
                    
                        IsFrmInvalid = True
                        
                        MsgBox PKeyName & " " & ctl.Parent(PKeyName) & " is Incomplete. Please complete record"
                        
                        ctl.SetFocus
                        
                    End If
                                      
                End If
    
    
            End If
        Next
    
    
    End Function
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  2. #32
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Well in that case you are allowed to sack the user.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  3. #33
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Quote Originally Posted by moke123 View Post
    You could try something along these lines. Undo changes to previous records or force completion of new records.
    thanks for replay
    1.Combo box will not be created in the product ID because the product is unlimited.
    2. It is impossible to edit the sub form in the program created by you. If a customer revises his order and cancels any item or meter, then how will it be deleted in the sub form.
    3. Mike has suggested a good method in post 4 and it also works but I want that delete button in sub form should not be created but should be coded in before update so that as soon as the user moves from blank row other row blank row auto deleted.
    Thanks for helping

  4. #34
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    then how will it be deleted in the sub form.
    So it's not a user inadvertently deleting entries, you are trying to delete the record by deleting only the visible part of the record.
    Use a delete button as previously suggested.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #35
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Quote Originally Posted by moke123 View Post
    With a delete button as previously suggested.
    but I want that delete button in sub form should not be created but should be coded in before update so that as soon as the user moves from blank row other row blank row auto deleted.
    Or all empty rows of the sub form will be automatically delete when the user saves the form.

  6. #36
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by deepaksharma View Post
    but I want that delete button in sub form should not be created but should be coded in before update so that as soon as the user moves from blank row other row blank row auto deleted.
    Or all empty rows of the sub form will be automatically delete when the user saves the form.
    All those 'empty rows' are actually records. except for the New row.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #37
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Quote Originally Posted by Welshgasman View Post
    All those 'empty rows' are actually records. except for the New row.
    Ok, so how to put the code in them that if shed and meter are empty then that record "empty record" gets deleted.

  8. #38
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by deepaksharma View Post
    Ok, so how to put the code in them that if shed and meter are empty then that record "empty record" gets deleted.
    I do not know how many times you need to be told.

    You code the BeforeUpdate event of the form to not allow records to be saved without the required data. Did you even look at that link I posted? :-(
    Then when you have that working, just create a query to get rid of the empty records.

    STOP the empty records being saved first, else you will always be chasing your tail.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #39
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Personally I would never do this, but you seem determined to do it this way.
    Use your own field names in the condition statement.

    Code:
    Private Sub Form_AfterUpdate()
    
    
        Dim rs As DAO.Recordset
    
    
        Set rs = Me.Recordset
    
    
        rs.MoveFirst
    
    
        Do Until rs.EOF
    
    
            If IsNull(rs!ProdID) And IsNull(rs!Qty) Then  'Use your own field names
     
                rs.Delete
     
            End If
    
    
            rs.MoveNext
        Loop
    
    
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  10. #40
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Quote Originally Posted by moke123 View Post
    Personally I would never do this, but you seem determined to do it this way.
    Use your own field names in the condition statement.
    101 cannon salute to you.
    It is working perfectly fine but I am facing two problems.

    1. While inserting a new record, when the cursor is moved to the meter field of the second row by the tab key in the sub form, the view of the cursor changes (as if the insert key is on) and have to press an extra tab. Why is this so? What is happening and how can I fix it.

    2. You have checked the black row by running a loop in the gray shade table to delete the black row. My guess is that when the amount of data in the gray shade table increases, this loop will take more time to run, which is likely to slow down the program. I was wondering if there is a sql query that will directly check the black row on the current record (main form offerid to sub form offerid) and delete it. What do you say.
    thank for your help.
    Attached Thumbnails Attached Thumbnails CURUntitled.png  

Page 3 of 3 FirstFirst 123
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Auto Text Insert In To A Blank Field In A Form
    By HectorTheInspector in forum Forms
    Replies: 8
    Last Post: 01-20-2017, 06:52 PM
  2. Replies: 4
    Last Post: 01-04-2016, 07:30 AM
  3. Replies: 2
    Last Post: 03-19-2014, 04:51 PM
  4. Code to delete the blank rows
    By drunkenneo in forum Programming
    Replies: 3
    Last Post: 02-17-2014, 09:26 PM
  5. delete record if 2 fields are blank
    By rlsublime in forum Access
    Replies: 1
    Last Post: 06-20-2012, 01:58 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