DoCmd.close Error (1 Viewer)

elfranzen

Registered User.
Local time
Today, 07:02
Joined
Jul 26, 2007
Messages
93
Why do I get an Error on the DoCmd.Close
Code:
Private Sub Score_Exit(Cancel As Integer)

UPDATESCOREPRINT = CardNumber2.Value


DoCmd.OpenReport "customerreceiptreprint", acViewNormal, , "[CardNumber2] = '" & UPDATESCOREPRINT & "'", , acHidden
DoCmd.OpenReport "receiptreprint", acViewNormal, , "[CardNumber2] = '" & UPDATESCOREPRINT & "'", , acHidden
Debug.Print UPDATESCOREPRINT
DoCmd.Close
DoCmd.OpenForm "EntryForm", acNormal, , , acFormAdd, acWindowNormal

End Sub
 

Moniker

VBA Pro
Local time
Today, 09:02
Joined
Dec 21, 2006
Messages
1,567
You opened two reports and then didn't specify what you want to close.

DoCmd.Close acReport, "ReportName"

Also (and holy crap, it happened again), using acViewNormal on a report opens it, prints it, and then closes it. There's nothing to close. Use acViewPreview if you want to see the report (and in turn have an object to close).
 

elfranzen

Registered User.
Local time
Today, 07:02
Joined
Jul 26, 2007
Messages
93
sorry I want to close the form that I am in once I am done editing the data

1. finish editing data
2. print the two reports
3. close the form I am in

2 and 3 could be flipped.

this doesn't work either

DoCmd.Close acForm, "UpdateRecordForm", acSavePrompt
 

elfranzen

Registered User.
Local time
Today, 07:02
Joined
Jul 26, 2007
Messages
93
Private Sub Score_Exit(Cancel As Integer)

UPDATESCOREPRINT = CardNumber2.Value


DoCmd.OpenReport "customerreceiptreprint", acViewNormal, , "[CardNumber2] = '" & UPDATESCOREPRINT & "'", , acHidden
DoCmd.OpenReport "receiptreprint", acViewNormal, , "[CardNumber2] = '" & UPDATESCOREPRINT & "'", , acHidden
Debug.Print UPDATESCOREPRINT
DoCmd.Close acForm, "UpdateRecordForm", acSavePrompt
DoCmd.OpenForm "EntryForm", acNormal, , , acFormAdd, acWindowNormal

End Sub
 

Moniker

VBA Pro
Local time
Today, 09:02
Joined
Dec 21, 2006
Messages
1,567
The OpenForm will have to go before the close. It will never be run otherwise.

What error, if any, is it giving you? To make sure I have the issue straight, you're opening a form of some sort, printing a pair of reports, and then trying to close the form. Correct?

Also, have you put in a breakpoint and traced where the code is going?
 

elfranzen

Registered User.
Local time
Today, 07:02
Joined
Jul 26, 2007
Messages
93
I get a Run-Time Error 2585 "this action can't be carried out while processing a form or report event.

and when I debug it selects then docmd.close code

I even tried opening the other form first then closing the last form but still doesn't work.
 

Moniker

VBA Pro
Local time
Today, 09:02
Joined
Dec 21, 2006
Messages
1,567
OK. It's not done printing the reports when it tries to close itself. I'm guessing these might be fairly large reports, or they might just take a little time to do calculations, formatting, etc.

Before the DoCmd.Close, have you tried putting a DoEvents? That should force it to complete everything else before attempting the close. To make sure that's right, place a breakpoint on the first open report command (click the left margin next to that line and it will highlight it in maroon), and then press F8 to step through the code. It'll probably work since you'll be manually going one line at a time. To DoEvents should accomplish the same thing.
 

elfranzen

Registered User.
Local time
Today, 07:02
Joined
Jul 26, 2007
Messages
93
They are two very short reports and I did step through made sure the printer was all done and took about 5 sec between each step. Still no go I even tried to close the form before the reports started printing still nothing even if I take out all the other line of code still get the error it has to do something with the reprot not closing. If I use the X button at the top and put the code to run on form close everything works but it just getting the dmcmd.close to work.
 

elfranzen

Registered User.
Local time
Today, 07:02
Joined
Jul 26, 2007
Messages
93
I also tried it as a macro and I get an error also
Macro Name: closeupdateformmacro
condition: True
Action Name: CLose
Arguments: Form, updateform. prmpt

says action failed
 

Moniker

VBA Pro
Local time
Today, 09:02
Joined
Dec 21, 2006
Messages
1,567
OK, I can't recreate this issue.

Have you tried putting the code in another event? I seem to remember something about the Exit event not handling closes correctly, but I could be remembering entirely wrong. That seems to be the issue though.
 

elfranzen

Registered User.
Local time
Today, 07:02
Joined
Jul 26, 2007
Messages
93
Lost focus the same thing. I only have one field to update and when they are done updated I want them to hit the enter key and close the form they are in print the two reports and open the main form. how else can I do this?
 

Moniker

VBA Pro
Local time
Today, 09:02
Joined
Dec 21, 2006
Messages
1,567
So, someone clicks a button on the main form. This opens a new form where the user enters some value into a field. That value is used as a parameter in a pair of reports, and then you want to close that update form.

Is there some reason we need a new form to open for the reports? Can the user not update a field on the main form and click a button on the main form to print the reports?
 

Users who are viewing this thread

Top Bottom