query stays open when form is closed (1 Viewer)

mkdrep

Registered User.
Local time
Today, 15:33
Joined
Feb 6, 2014
Messages
176
This has never happened to me before.

Top left corner of attached (.jpg) shows the (4) buttons which I created in an idential fashion on my main form. The only time the "issue" arises is when I click on the "ASI" Button...the other three buttons work properly.

When I click on the ASI button both the [frm_ASI] and it's underlying query [qryASI-Quote-FU] open. When I click the close button on [frm_ASI], the form closes but the query stays open.

Any suggestions as to why it is happening in only this one case?

Thank you.....Mark
 

Attachments

  • Query_Opening_with_form.pdf
    65.1 KB · Views: 36

theDBguy

I’m here to help
Staff member
Local time
Today, 12:33
Joined
Oct 29, 2018
Messages
21,358
Hi Mark. Can you post the code for your button? Also, are there any code behind the form that may be opening the query?
 

mkdrep

Registered User.
Local time
Today, 15:33
Joined
Feb 6, 2014
Messages
176
thank you for the reply
There isn't any underlying code for the form

Here is the code behind the ASI button:


Private Sub open_frm_ASI_2_Click()
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frm_ASI"
stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_frm_ASI_Click:
Exit Sub
Err_frm_ASI_Click:
MsgBox Err.Description
Resume Exit_frm_ASI_Click
End Sub


Just for comparison, this is the code for the Pawling button, which seems to be pretty much the same with the exception of a different form name. They underlying "Pawling" query does NOT open up....

Private Sub open_frm_Pawling_Click()
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frm_Pawling"
stLinkCriteria = "[ID]=" & Me![ID]

DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_frm_Pawling_Click:
Exit Sub
Err_frm_Pawling_Click:
MsgBox Err.Description
Resume Exit_frm_Pawling_Click
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:33
Joined
Oct 29, 2018
Messages
21,358
Okay, thanks. Just for fun though, open your database and close all objects. Then, go to the Immediate Window and type the following:
Code:
DoCmd.OpenForm "frm_ASI"
If the form opens, close it and see if the query is open behind it.
 

mkdrep

Registered User.
Local time
Today, 15:33
Joined
Feb 6, 2014
Messages
176
I have the database open per your request, and other than the ribbon, nothing but white space is staring back at me.

sorry to be such a dunce, but where do I find the "Immediate Window" to type in the code?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:33
Joined
Oct 29, 2018
Messages
21,358
Sorry. Hit the Ctrl+G key combination and just start typing as soon as the other window opens.
 

mkdrep

Registered User.
Local time
Today, 15:33
Joined
Feb 6, 2014
Messages
176
Aha! thx

Ran DoCmd.OpenForm "frm_ASI" and both the form and query opened up.

Again, just for comparison I entered
DoCmd.OpenForm "frm_Pawling" and only the Pawling form opened up
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:33
Joined
Oct 29, 2018
Messages
21,358
Aha! thx

Ran DoCmd.OpenForm "frm_ASI" and both the form and query opened up.

Again, just for comparison I entered
DoCmd.OpenForm "frm_Pawling" and only the Pawling form opened up
Okay, the code I asked you to enter would have not opened the query for you. So, I still suspect the form is doing it. So, as another experiment, again close all objects but make sure you can see the Navigation Pane. This time, simply open frm_ASI from the Nav Pane by double-clicking it. Did the query open too?
 

mkdrep

Registered User.
Local time
Today, 15:33
Joined
Feb 6, 2014
Messages
176
Yes, both the form and query opened up.
 

mkdrep

Registered User.
Local time
Today, 15:33
Joined
Feb 6, 2014
Messages
176
I have a button on the [frm_ASI] which runs the [qryASI-Quote-FU] when clicked. I copied and renamed [frm_ASI2], deleted the button which runs the [qryASI-Quote-FU], debugged the new form.

I opened up [frm_ASI2] and the query still opened up with the form
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:33
Joined
Oct 29, 2018
Messages
21,358
Okay. The next step is to check all the code behind the form. For example, do you have any code in either the Open or Load event of the form?
 

mkdrep

Registered User.
Local time
Today, 15:33
Joined
Feb 6, 2014
Messages
176
Bingo! for some reason, under the Event tab/On Current there was an event process advising form to open up the offending query! I am not sure how it go there, but once I deleted it, I could open the form without the query opening.

Same old story, garbage in, garbage out! lol

Thank you very much for being patient with me and walking me through the steps to solve this problem :)
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:33
Joined
Oct 29, 2018
Messages
21,358
Hi. Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom