I seem to be having trouble closing a Pop-up Modal form that is used as a dialog box to allow user input. The dialog box has 2 options, Continue and exit. If the user selects "continue" then this runs a macro to open up another form using a particular filter. What is supposed to happen then is that the dialog box is supposed to close. HOWEVER, it won't or creates an error message.
If I include in the macro a SelectObject command and then a Close command the dialog box closes but an error message pops up "The expression you entered refers to an object that is closed or doesn't exist"
If instead of putting the command in the macro I put it in the new opening forms OnLoad Event It bomns out in error
The dialog form doesn't appear in list of Access windows, but it is still in the background.
What is the correct way to close a pop-up modal form?
Yep its still there as when I change it to from dialog/modal/pop-up to full size I can see it.
If I then take the code of Close from the OnLoad Event then I can see it and I get no error message.
As soon as I put the code back in I get the error message
The spelling is correct as I've even used the rename facility on the form and copied and pasted that to code, still no joy.
Thanks for the suggestion as it wouldn;t be beyond me to mis-spell etc !!!
I think Teddy is right- it must be some simple answer. Try running the code somewhere else whilst your dialog form is open e.g. in the immediate window or quickly create a button to run it. If you know that the docmd.close code is right, then at least you narrow it down to something happening between the continue button being pressed and the form opening. Do you have any other code running when the continue button is pressed?
Last edited by pootle flump; 05-05-04 at 13:19.
Just wanted to try to help you out here. First, if you would Zip and Attach a copy of your database(pertinent info removed) or just the Form itself I will look at it and try to help. I have several DialogForm I use in my database and have no problems with any of them. I have some that set criteria/parameters for queries, and open other forms and reports.
1. Not sure what baggage macros bring along with them. Got an early start on doing all my stuff in VBA and it's really cool and powerful.
2. I am pasting a copy of my code behind one of my DialogBoxes to show you. But I have NO CODE set for the form itself. Only coded the buttons that will do the work in fetching the data for me.
3. The form has a TextBox for users to input the info they wish to find. Next they Click the command button that goes to find the data, opens the report and closes the DialogForm.
4. My form is set to PopUp=Yes, Modal=No, BorderStyle=Dialog. That's about it...so here below is the ONLY code I have for my DialogForms....except the one that just Cancels it out if need be.
Private Sub cmbJobChargesRpt_Click()
On Error GoTo Err_cmbJobChargesRpt_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "rptJobChargesByJob2"
stLinkCriteria = "[JobID]= " & " '" & Me![JobID] & "'"
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
DoCmd.Close acForm, "frmJobChargeByJobDiag"
Select Case Err.Number
Case 2501 'Empty report
Hope this helps you out. If not do attach something to work with and will be glad to try to help you more.
When a user clicks the continue button, does the next form use a value from the form you are trying to close? If that is the case you may want to use a VBA behind your button intstead of a macro and I could show you how to pass a value from one form to the other and close one. It all takes a few seconds.
I have a search form and it closes after passing the PartID to the next form. I think this maybe a similar situation. Please let me know if this is the case.
I have quite a few instances of a Pop Up form being closed and then other forms and actions occuring.
I will describe the sequence and macro actions of one for you. The last part of the post in bold is what happens when I click a lable to run a macro that closes the Pop Up.
The Pop Up form is a calendar that is opened from a main form that is open.
When a date is clicked there a macro runs that has 3 Setvalue actions applied to the MainForm, then it makes Visible a a combo box drop down with a time listings and it makes the combo box open, that is, drop down its time listings.
When the time on the combo is clicked that are several SetValue actions (After Update) run and they involve both the Pop Up form setting values in the MainForm and also the MainForm setting a value in the Pop Up form. The last action is SelectObject, being the MainForm.
The time drop down combo also has a macro running On Click which sets value to the MainForm from the combo and it also makes a Close label visible and it SelectsObject again and that being the MainForm
When the Close label is clicked a macro runs and the first action is Save Record, the next action is the Pop Up form is closed, then another SaveRecord. It then opens another form (not Pop Up) and then there are several SetVale actions run that set the values on this newly opened from from the MainForm. The macro then close this form and again SelectObjects is done for the MainForms
Firstly apologies for the delay in replying to you all, I have been off ill for a few days.
I've now cracked the problem by including in the command button from the Pop-up form the close command . Why this works here and not in the macro or in the Onload command of the opening form is beyond me.
Once again I checked that the form was open by changing it from dialog/modal/pop-up to full size and took any reference to closing the form from the macro or anywhere else out. I could then see that the form was still open, when I then changed the macro to close the form after opening the main form, I got the same error message!!!!!! Don't understand that but anyhow it is now solved as described, I gues it will be one of those things that I'll never get to the bottom of