closing a form

Posted on 2003-02-23
Medium Priority
Last Modified: 2012-06-27
Sorry if this seems like a silly question but.....

I have a form which has various text input boxes. One of the inputs (along with one other field) makes up the primary key.  I've set up a message box that prompts the user if an invalid ID has been input.  This works fine.  The message box has RETRY and CANCEL buttons.  I've been able to get the retry to work without any problem - I just send the user back to the text box to have another go.  For the cancel button though, I would like to close the form completely (and go back to a main menu when I set one up).  When I try to do a

DoCmd.Close acForm, "Initial", acSaveNo

command I just get a

Run-time error '2585': "This action can't be carried out while processing a form or report event."

I've tried saving the record first, running the command from a module rather than inside the form code, saving the record then deleting it and lots more I can't remember.  I feel like I must be missing something really obvious.
I hope this all makes sense (and it's an easy one...)
Thanks in advance,
Question by:damien232
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8006412

are you using

retvalue = MsgBox("Continue?", vbOKCancel)
    If retvalue = 2 Then
    End If

something like that?
LVL 41

Accepted Solution

shanesuebsahakarn earned 150 total points
ID: 8006463
As the error suggests, there are some event procedures in which you can't carry out a DoCmd.Close acForm action (for example the LostFocus and Exit event procedures).

You can try some alternative designs to get round this problem. One way might be to remove the cancel button on the message box and provide cancel and OK buttons on the form itself. You can disable the OK button until the user enters a valid ID and just enable it when appropriate.

Expert Comment

ID: 8006559
Have you tried using the before-update event instead of lost focus??
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.


Expert Comment

ID: 8007070
Give this a try, don't know if it will work but I've been using it and it's ok:

DoCmd.Close acForm, me.Name, acSaveNo

Otherwise, could you past the code which has the retry/cancel options? This may help us help you.

Author Comment

ID: 8013227
Thanks for the help.
I've sort of worked it out (with a dodgy workaround).  I added a CANCEL button to the form (as suggested by shanesuebsahakarn) and then made the cancel button on the dialog box clear the invalid input and send an ESCAPE character which is then effectively the same as clicking the cancel button.


Author Comment

ID: 8013231
I partially used your advice with a flash of insight and some more trial-and-error on my part.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question