Results 1 to 3 of 3
  1. #1
    ETCallHome is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    Limpopo, South Africa
    Posts
    48

    Talking Form does not close... keep popping up MsgBox Error message

    Hi,

    Calling on all the experts to assist this dumb guy with Access form programming...



    I created a form (DataMode = Add) with with validation for all required fields in the OnExit Event for the fields. However, I open the form and then decide to do one of 2 things...

    1. Decide not to add any record and press the exit CmdButton that closes the Form, or
    2. Add the necessary data and after the record was added, press the exit CmdButton that closes the Form...

    In Both instances... it keep popping up the MsgBox that I created prompting me to enter the required fields, and does not want to exit. Is there a way that when the exit CmdButton is pressed that all events on the form is disabled.... I Wonder.... !!! I am going to check whether the is a property that disables an event... maybe this will help.

    But you expertise is highly appreciatetd.

    Thanks

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    If you want to continue using the OnExit event of each control then create a Public variable above all of the event procedures and watch it in your OnExit code. You can change it in the Click event of the Exit cmdButton.

  3. #3
    ETCallHome is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    Limpopo, South Africa
    Posts
    48
    Hi Allan,

    I put the validation code for each field on the CmdButton event OnEnter, and also created a nested If Statement for the validation as apposed to individual If Statement, i.e.

    If isnull(A)
    msgbox "error"
    else
    if isnull(b)
    msgbox "error"
    .
    .
    .
    This ensured that this validation is only done when the cmdbutton to open the other form is execute, therefore the form will only open when all the fields are correctly populated. I also put the same code into the BeforeUpdates on the Form, thereby ensure that only if data was entered then the validation will be executed before the savecmd. This allowed me to undo any changes and then exit or just exit.

    I tried putting the validation in a public sub procedure that I created in the code builder, i.e. Check_Validation and the code looks as follows:

    If A = ....
    call Check_Validation
    .
    .

    Sub Check_Validation(Cancel As Integer)
    cancel = true
    msgbox "Error"
    me.A.setfocus

    This is to prevent have to maintain the validation code in more than one place, however, when I execute it it returns a compile error "expected: list separator or)" I have search the Internet for answers... but not getting anything that assist me. Can you help me with this problem..

    I changed the code as follows

    if A = ....
    call Check_Validation(Cancel As Integer)

    It then complains about invalid arguements....

    It is now 23h40 in South Africa and I am dead tired as I need to have a Pilot run on the developed software ready by tomorrow.

    Thanks

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

Similar Threads

  1. Error Message
    By Juan4412 in forum Forms
    Replies: 5
    Last Post: 03-06-2011, 04:22 PM
  2. Access Form- Save/Close Button error
    By Ashe in forum Forms
    Replies: 3
    Last Post: 02-10-2011, 01:01 PM
  3. Replies: 1
    Last Post: 12-02-2010, 03:04 PM
  4. Replies: 3
    Last Post: 11-22-2009, 07:46 AM
  5. If / Then Error Message
    By Schwagr in forum Forms
    Replies: 4
    Last Post: 03-30-2006, 06:28 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