Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit and close a form while opening another

Status
Not open for further replies.

gsfmike

Programmer
Oct 20, 2000
21
0
0
US
I am attempting to exit a field (text box) on form1 with a value and use it to open another form - form2. I am using DoCmd.Close to close form1. I get:
Run-time Error 2585

This action can't be carried out while processing a form or report event.

I have tried to put the close command in various places and I still get the error. I have assigned the value to a temp string hopefully to not have and connection to the form being closed.

Any thoughts on this - anyone?
 
Hi,

Try running your code in this order:
- change names of elements to match your elements in your froms

DoCmd.OpenForm "Form2"
Forms!Form2.TextBox = Me!TextBoxFromForm1
Forms!Form2.TextBox.SetFocus
DoCmd.CloseForm "Form1"

HTH,

jbehrne If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
have you tried using macros? i have made this work using macros.. Tejanorey

"Do not attack the First Marine Division. Leave the yellowlegs alone. Strike the American Army."
- Orders given to Communist troops in the Korean War; shortly afterward, the Marines were ordered to not wear their khaki leggings to keep the enemy from immediately fleeing
 
i want to know the same thing but iam not profound in codees....Can help? I just know how to use access..
 
thread702-494921
Tejanorey

"Do not attack the First Marine Division. Leave the yellowlegs alone. Strike the American Army."
- Orders given to Communist troops in the Korean War; shortly afterward, the Marines were ordered to not wear their khaki leggings to keep the enemy from immediately fleeing
 
to BRY12345 Here is the Code:

Private Sub Text0_Exit(Cancel As Integer)
Dim txval As String
txval = Me.Text0

If txval <> &quot;&quot; Then
' DoCmd.Close
DoCmd.OpenForm &quot;frm_shipping&quot;, acNormal

Forms!frm_shipping.PO_Time.SetFocus
DoCmd.Close acForm, &quot;frm_getPO&quot;


Else
MsgBox &quot;Enter Po NUmber&quot;
End If

End Sub

The line highlighted during the error is the DoCmd.close line.

To jbehrne: This what I had but I could not get the DoCmd.CloseForm to work

Thanks for the repsonses.
 
Try something more along these line:

Private Sub Text0_Exit(Cancel As Integer)

if IsNull(Me!Text0) then
Msgbox &quot;Please enter a PO Number&quot;
DoCmd.CancelEvent
Exit Sub
End if

DoCmd.OpenForm &quot;frm_shipping&quot;
DoCmd.Close acForm, &quot;frm_getPO&quot;

End Sub


You probably want to do the SETFOCUS in the 2nd form's OPEN event instead. I find it less confusing to have actions like that coded in their own modules, rather than in other form's modules. Makes it easier to track down boo-boos.

You also might investigate the OPENARGS process if you want to pass a value from one form to another.

Jim


Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
Wildhare

Thanks for the suggestion and the thoughts on keeping actions in their own modules. It does make it easier to know what is going on.
I have used your code sample and unfortunately the same error occurs:
This seems so simple, I must be missing something.
This is the task. A very simple form (1 unbound text box)requesting the entry of a value. I want to use that value and open another form by finding a record based upon the value, display the information... or if no record is found just display a blank form. The only problem (The referenced error) is I want to clean up the desktop by closing the form where I requested the data.
The key seems to be the processing term in the error message.

Thanks for any thoughts.
 
Why not uncomplicate things a bit - if your first form just has the text box, why not combine things, and put the text box in a form's header section, and use the detail section for your record controls. Also, depending on what you are actually doing, it might be just as easy to use a combo box with a list of the PO numbers, allowing the user to select the one they want, and then positioning and displaying that record on the form.

I'm not sure what's causing the &quot;DoCmd.CLOSE..&quot; guy to barf like that, it might be that there's some kind of random corruption in the form. Normally, &quot;Close&quot; is fairly reliable. :)

What else have you tried?

J

Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
WildHare;
I have uncomplicated the process.... but I can't leave it alone as to why the close function is causing the error. I wanted this to be a simple - Enter value - Display information - continue. (Too much information confuses some of the folks here.)

Anyway .....
I will spend some time playing with this later. Thanks for the input.
 
GSFMike,

I see no reason Jim Hare's suggestion DoCmd.Close acForm, &quot;frm_getPO&quot; shouldn't work.

To test for the possibility of corruption, I think I would design a simple test form with the same button and see if that one closes. While the test form doesn't mirror the form you are having a problem with, chances are there is nothing you coded on the form which is precluding it from closing. I agree with Jim . .probably corruption on the form. - - - -

Bryan
 
Bryan, Lesson learned.... when things don't make sense - Restart:

I created another simple form and the code in the After Update event worked as it should (The form was closed). The problem seems to have been I chose the On Exit event. That event won't allow the form to be closed, in either my original form or the test form. Don't know why I chose On Exit event but anyway....

Thanks to all for the help!!
 
Hey....I got another way toclose and open form.You can use macro for that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top