Results 1 to 2 of 2
  1. #1
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246

    Cant get sub form to execute code when user leaves sub form.

    I have a parent form with three sub forms:

    Entity Form = Parent
    Address Sub Form = Child
    Phone Form = Child
    Email Form = Child



    The end user enters the entity First Name and Last name and then tabs to the Address Subform. In the address sub form the user can enter several addresses such as Home, Work, etc. The end user must check one of the addresses as "Main" in the Main Check box. See form.

    Click image for larger version. 

Name:	TestExitForm2.jpg 
Views:	8 
Size:	63.7 KB 
ID:	21315

    The end user enters all addresses. When the user is done and exits the sub form I want the code to test and make sure one of the Addresses is checked as main. My Query and Code seems to work fine.

    Query "TestAddressForMainChk" This works fine when run independently.

    SELECT dbo_EntityAddress.MainAddress
    FROM dbo_EntityAddress
    WHERE (((dbo_EntityAddress.MainAddress)=[Forms]![EntityFRM]![EntityAddressFRM].[Form]![Main]));

    The following code executes fine seems to work fine and is captured by the Query.
    Code:
    Private Sub EntityAddressFRM_Exit(Cancel As Integer)
    Dim intRecordset As VariantintRecordset = DCount("*", "TestAddressForMainChk")
    If intRecordset = 0 Then
       Call MsgBox("One Address must be checked as Main." _
       & vbCrLf & "" _
       & vbCrLf & "Click OK to  exit and check Main Address." _
       , vbExclamation, "Missing Data")
       Exit Sub
    End If
    End Sub
    This is a data quality check. They can enter as many addresses as they want but they must check MAIN for one, before they can exit the address sub form.

    The code is currently loaded in Address FORM.

    I have tried it On Lost Focus, On Deactivate, ON Unload but none of them are working. So each component works fine. But together on the form they won't work.

    What am I missing? I need to do this, or something like it, in many different parts of the DB.

    Thanks

    Phred

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    MsgBox has two formats, one is just an information popup, the other is a function. When used as a function by incorporating () it must be on the right side of an expression, like:

    intResponse = MsgBox("message", vbYesNo, "Missing Data")

    Remove the () to invoke as information only:

    MsgBox "message", vbExclamation, "Missing Data"

    No need for Call.
    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.

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

Similar Threads

  1. vba code help - Currentdb.execute
    By joycesolomon in forum Programming
    Replies: 5
    Last Post: 08-11-2014, 11:25 AM
  2. front end code with user form
    By gammaman in forum Programming
    Replies: 1
    Last Post: 07-19-2013, 02:39 PM
  3. HELP>Access 2010 User Login Form Code.
    By zaaimanm in forum Programming
    Replies: 5
    Last Post: 10-22-2012, 07:28 PM
  4. How to execute Line of Code
    By jo15765 in forum Programming
    Replies: 4
    Last Post: 06-22-2011, 05:37 PM
  5. Can't get any of my code to execute!
    By blacksaibot in forum Programming
    Replies: 4
    Last Post: 03-16-2010, 08:08 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