Close Form In This Code

fenhow

Registered User.
Local time
Today, 14:06
Joined
Jul 21, 2004
Messages
599
Hi,
How do I close the form this code is on if the user chooses yes?

Can anyone show me how to do this?

Thanks.

Fen

Private Sub SFVINFen_GotFocus()

If Me.SFVINFen.ListCount = 0 Then
If MsgBox("VIN Does Not Exist! Would You Like To Continue With The New Order?", vbQuestion + vbYesNo, "VIN NOT FOUND!") = vbNo Then
Exit Sub
Else
Dim stDocName As String
DoCmd.OpenForm "Order Details", acNormal
DoCmd.GoToRecord , , acNewRec
Forms![Order Details].VIN.Value = Me.VinToFindFen
Forms![Order Details].ROFirst.Value = Me.FirstNameToFindFen
Forms![Order Details].ROLast.Value = Me.LastNameToFindFen
End If

End If

End Sub
 
Hi,
How do I close the form this code is on if the user chooses yes?

Can anyone show me how to do this?

Thanks.

Fen

Private Sub SFVINFen_GotFocus()

If Me.SFVINFen.ListCount = 0 Then
If MsgBox("VIN Does Not Exist! Would You Like To Continue With The New Order?", vbQuestion + vbYesNo, "VIN NOT FOUND!") = vbNo Then
Exit Sub
Else
Dim stDocName As String
DoCmd.OpenForm "Order Details", acNormal
DoCmd.GoToRecord , , acNewRec
Forms![Order Details].VIN.Value = Me.VinToFindFen
Forms![Order Details].ROFirst.Value = Me.FirstNameToFindFen
Forms![Order Details].ROLast.Value = Me.LastNameToFindFen
DoCmd.Close acForm, "FormNameYouWantToClose"
End If

End If

End Sub

Hey Fen,
Take a look at the line in red above and add it to your code. I believe it will do what your looking for.

HTH,
Shane
 
Thanks Shane,

Here is what I am running into - I get an error that says;

This action cant be carried out while processing a form or report event..

Any suggestions?

This code is on the controls "On Focus" event of the form I am trying to close..

Fen
 
I get an error that says;

This action cant be carried out while processing a form or report event..
Sounds right to me. :)
This code is on the controls "On Focus" event of the form I am trying to close..
Fen,

If I may pose an interesting question here:

How can a form close when it is in the process of running one of its own events? When I first read this, I didn't catch it either, but the error makes sense if you think about it this way! That's just a "chime-in". A little logic...
 
Adam,

I understand, I guess when the other form opens I want this form to close... Should I run the close command on the form that opens...?

Fen
 
Should I run the close command on the form that opens...?
Well, I suppose it depends. Are you ever going to be opening the "opened" form another way? Or will it always be opened from the "active" form you are referring to in this situation? If it will never be opened another way other than by this method, just use Shane's line of code with the OnLoad event of the "opened" form.

But, if the above stipulations will not always be correct, then you will have to check a condition of somekind that refers to the "active" form. This will be a test to see if it is open or not.
 
The problem is that some process is apparently still running on you first form, preventing its closure. You have the code in the SFVINFen_GotFocus event, whcih I assume, from the code If Me.SFVINFen.ListCount = 0 Then is a listbox/combobox. How is this control populated. A process that is runs and won't allow a form to code makes me think maybe you've got an endless loop situation.

When you posted this same question a few days ago, Bob Larson suggested that you try moving the code to a different event; did you try that and what happened?

It might be helpful if you gave us an overview of exactly what you're trying to do here.
 
Hi, Thanks.

Yes I tried moving the code to a different event and It still would not close. I am sorry about the double post..

Here is what I am trying to accomplish:

I have a form called "Order Details"

When the user wants to enter a new order i have a button on the "Order Details Form" that opens another form called "New Order VIN Verify" this window pops up in front of the "Order Details Form"

The user enters three lines of information into the "New Order VIN Verify" form, the form then checks via unbound text boxes and a list box for duplicate entries already existing in the database.

If it finds one or not the user is prompted to their next action by way of If Msg..

Either way they are directed back to the "Order Details Form". The problem is when they leave the "New Order VIN Verify" form and go back to the "Order Details Form" the "New Order VIN Verify" stays in focus and open. The user has to physically close it and or move it out of the way.

I just took the is pop up yes off but I still have the issue..

Thanks.

Fen
 
Hi, I just discovered if I make is popup no the search will not work at all.. so it has to be on..

Fen
 
My guess is you had it set to Popup = Yes and Modal = Yes.

From Help:
"You can use the Modal property to specify whether a form or report opens as a modal window. When a form or report opens as a modal window, you must close the window before you can move the focus to another object. "

See if Modal is set to Yes, and if it is change it to No and the code to close it should work. I'm not at a machine with Access on board so I can't check this from my end, but it's easy enough for you to check.

Linq
 
Hi,

Modal is no. I never guessed closing a form would be so hard.

Can I put this code somewhere on the Order Details form so when I the IfMsg goes to the Order Detais form the frm NewOrderVINVerify closes??

DoCmd.Close acForm, "frm NewOrdeVINVerify", acSaveNo

Thanks.
 
Fen, do me a favor, if you would: Test this and see if it works...

Private Sub SFVINFen_GotFocus()

If Me.SFVINFen.ListCount = 0 Then
If MsgBox("VIN Does Not Exist! Would You Like To Continue With The New Order?", vbQuestion + vbYesNo, "VIN NOT FOUND!") = vbNo Then
Exit Sub
Else

DoCmd.Close
End If
End If

End Sub
 
Hi Adam,

This is what I get.

This action cant be carried out while processing a form or report event..

Fen...
 
I have two other questions for you Fen:

1) Why are you using the code from post #1 with a GotFocus Event of a control? That doesn't make much sense to me anyway!
2) What does you screen name mean?
 
Tried it.. whew what the heck.. Here is the code I am working with

Private Sub SFVINFen_GotFocus()

If Me.SFVINFen.ListCount = 0 Then
If MsgBox("VIN Does Not Exist! Would You Like To Continue With The New Order?", vbQuestion + vbYesNo, "VIN NOT FOUND!") = vbNo Then
Exit Sub
Else
Dim stDocName As String
DoCmd.OpenForm "Order Details", acNormal
DoCmd.GoToRecord , , acNewRec
Forms![Order Details].VIN.Value = Me.VinToFindFen
Forms![Order Details].ROFirst.Value = Me.FirstNameToFindFen
Forms![Order Details].ROLast.Value = Me.LastNameToFindFen

End If
DoCmd.Close acForm, "frm NewOrdeVINVerify", acSaveNo
End If

End Sub

Keep in mind this control is on the form that i want to close...

SFVINFen

Fen How
 
If MsgBox("VIN Does Not Exist! Would You Like To Continue With The New Order?", vbQuestion + vbYesNo, "VIN NOT FOUND!") = vbNo Then
DoCmd.Close acForm, "frm NewOrdeVINVerify"
Exit Sub

Scrap the acSave, it does nothing
 
This problem can be fixed in a second if you just move all of this code and put it with a button instead of a control "action" event. Why can't you do that?
If MsgBox("VIN Does Not Exist! Would You Like To Continue With The New Order?", vbQuestion + vbYesNo, "VIN NOT FOUND!") = vbNo Then
DoCmd.Close acForm, "frm NewOrdeVINVerify"
Exit Sub
He can't do this Rich! The rest of the code is copying values from the current form! If he closes the form first, the rest of the code won't run.
Scrap the acSave, it does nothing
Yes, absolutely.
 
Adam,

I am using an unbound textbox to search the databse for duplicates before the user moves on to the new entry. The got focus of the listbox is triggered by a macro that requerys the listbox based on the txtbox data.. Once the data is searched depending on the result, by way of IF txtmsg the user is prompted to move foward..

My screen name FenHow?

Fen
 
The got focus of the listbox is triggered by a macro that requerys the listbox based on the txtbox data..
Fen,

This statement is not true, because requerying a list box without a physical click of the mouse on it does not trigger the got focus code to run. I hate to say this, but I am getting nowhere trying to understand you're problem. Is it possible that you can provide a few screenshots? Or even better, your database, or a sample (small) database that shows your process, AND your problem??
My screen name FenHow?
YES! :)
 

Users who are viewing this thread

Back
Top Bottom