Results 1 to 5 of 5
  1. #1
    robsworld78 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    181

    Need a set of records in a subform to be complete before closing form

    Hi, I've made a form what has a subform, the subform is auto populated with records after someone updates a combo box. Next the person needs to fill in an empty "text" field with data for each record in the subform, the number of records always changes.



    Sometimes a record can be missed and that messes things up. I can't turn on "requires data" for the field because the records are being auto created.

    I've been trying to make code that will go to the first record in the subform and then scroll through the records and if a specific field is empty in that record it will pop a message and exit sub. If it gets through all the records without that field being empty it can close.

    I've been playing with loops and recordsets and at one point thought I was close but can't get it.

    Any help would be appreciated!

  2. #2
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Your biggest problem is to decide what event triggers the examination of the records comprising your subform. I'm not too sure which event I would use; let me ponder awhile.

    Otherwise the examination is easy. Your subform has an underlying recordset. You need to loop through this recordset testing the text field in each record and, if empty, take the appropriate action. I would recommend you use a clone of the recordset for this, not the recordset itself. Why? I believe if you use the recordset there could be a lot of activity in the subform.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    Yes, the real trick is figuring out what event to put code in. Maybe the form Close. Or disable the X close button and use a command button to 'Save/Exit'.

    I agree, use RecordsetClone, something like:

    Sub SaveExit_Click()
    With Me.RecordsetClone
    .FindFirst "IsNull(fieldname)"
    If Not .NoMatch Then
    MsgBox "Missing data for 1 or more records"
    Me.Bookmark = .Bookmark
    'do not close form
    Exit Sub
    Else
    DoCmd.Close acForm, Me.Name, acSaveNo
    End If
    End With
    End Sub
    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.

  4. #4
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    I was considering the On Exit event of the subform control. It can be cancelled if a problem is discovered. However this assumes that the subform will be given the focus, which is not necessarily true if the user simply browses in the master form and never enters the subform.

    There again if user intervention is not required the need to use a cancel-able (horrible English) event is negated and all events become candidates.
    Last edited by Rod; 03-24-2013 at 10:35 PM.

  5. #5
    robsworld78 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    181
    Ah thank-you so much, I was complicating it to much. Finding where to put the event is easy but making the event usually isn't. I have "post" buttons on forms and no x in corner to close.

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

Similar Threads

  1. Auto complete between tabs in Form
    By Hamm in forum Forms
    Replies: 3
    Last Post: 10-25-2012, 08:38 AM
  2. Auto complete field on form
    By oam in forum Access
    Replies: 5
    Last Post: 09-23-2011, 12:45 PM
  3. Dlookup to auto complete in form
    By custhasno in forum Access
    Replies: 2
    Last Post: 09-08-2011, 12:53 PM
  4. Closing a form automatically
    By accessnewb in forum Forms
    Replies: 27
    Last Post: 07-22-2011, 05:58 PM
  5. Closing a form through VBA
    By ghostmachine in forum Forms
    Replies: 4
    Last Post: 12-13-2010, 01:57 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