Dismissing a Form (1 Viewer)

sja13

Professional Idiot
Local time
Today, 18:49
Joined
May 3, 2017
Messages
63
Thnks to some great advice from forum members I was able to achieve opening a form using the following suggested code
Code:
  strForm = "frmReportFilter"
  DoCmd.OpenForm FormName:=strForm, _
                 View:=acNormal, _
                 DataMode:=acFormPropertySettings, _
                 WindowMode:=acDialog

The Form (which doesn't refer to Tables or Queries for any of its data sources) is visible, and I can interact with it.

My problem is now dismissing the form.

I have a couple of buttons on the form (effectively "Do it" and "Quit"), and when they are clicked, in the button's Click event I coded
Code:
  DoCmd.Close acForm, _
              Me.Name, _
              acSaveNo
The form doesn't close!
I also tried
Code:
  DoCmd.Close acForm, Me.Name
with the same lack of effect.
I've spent a few hours with Mr. Google, and AWF's search engine, but everything I've found suggests the code should work.

I suspect it may be related to either the Datamode or Windowmode, but I can't find anything about those parameters that suggests they require a special form of Close command.

Any helpful soul got any ideas???
 

Ranman256

Well-known member
Local time
Today, 13:49
Joined
Apr 9, 2015
Messages
4,337
all you need to close the form is:
DoCmd.Close
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 10:49
Joined
Aug 30, 2003
Messages
36,133
What you have should work. Has the code lost its association with the button? Can you attach the db here?
 

isladogs

MVP / VIP
Local time
Today, 18:49
Joined
Jan 14, 2017
Messages
18,261
This DOES work:
Code:
 DoCmd.Close acForm, Me.Name

However DoCmd.Close is enough to close the ACTIVE form.
You only use the longer version if its not clear to Access what exactly needs to be closed e.g. something else has focus

BTW you could open the form with those same conditions using this shorter code:

Code:
DoCmd.OpenForm "frmReportFilter", , acFormPropertySettings, acDialog

acNormal is the default so can be omitted

I've NEVER used acFormPropertySettings
Out of interest why do you need it?
 

Minty

AWF VIP
Local time
Today, 18:49
Joined
Jul 26, 2013
Messages
10,374
I concur with Ridders - I'd remove the acFormPropertySettings

Code:
DoCmd.OpenForm "frmReportFilter", , , acDialog
It was a copy and paste from the MS site - apologies if it's caused an issue. (Can never remember the correct number of comma's to put in...) :eek:
 

sja13

Professional Idiot
Local time
Today, 18:49
Joined
May 3, 2017
Messages
63
To Paul and Colin....

First - I've no idea (as usual) why I have to use acFormPropertySettings - it was code which Paul kindly supplied when I was having problems getting the Form to stay on screen so that I could interact with it.
If you need further details, that thread is at:
https://www.access-programmers.co.uk/forums/showthread.php?t=295612&goto=newpost

Next - I've spoken to The Boss, who is not happy at having his Db posted
(he uses the Db to manage a collection of valuable items).

What I am allowed to do is post screenshots.
In sequence, these are
  1. Report Request screen in foreground, with "calling" screen in background
  2. VBA behing Run button prior to close
  3. VBA behind Run button during close
  4. VBA behind Run button after close
  5. Report Request Screen still showing
Inspection of the standard "step thru" shows that the close command is being executed, but not very effectively.
 

Attachments

  • 1 Filter Form.jpg
    1 Filter Form.jpg
    59.9 KB · Views: 69
  • 2 RunCmd VBA.jpg
    2 RunCmd VBA.jpg
    88.5 KB · Views: 73
  • 3 RunCmd VBA.jpg
    3 RunCmd VBA.jpg
    89 KB · Views: 78
  • 4 RunCmd VBA.jpg
    4 RunCmd VBA.jpg
    88.8 KB · Views: 74
  • 5 Back at screen.jpg
    5 Back at screen.jpg
    59 KB · Views: 83

sja13

Professional Idiot
Local time
Today, 18:49
Joined
May 3, 2017
Messages
63
Removed code as suggested - still does exactly the same thing.
Oddly, if I click the Run button a second time (after the first click which seems to do nothing), it works as it should!
 

isladogs

MVP / VIP
Local time
Today, 18:49
Joined
Jan 14, 2017
Messages
18,261
1. We always tell users to make a copy of their db then remove any confidential data & irrelevant items before uploading.
Hopefully your boss would be happy with that

2. Click Run twice ....
Umm... you haven't got the code in the Double_click event rather than the Click event by any chance?
Otherwise, sounds like the button hasn't got focus for some reason so it has to be clicked twice

Just out of interest try opening the form not in dialog mode
Code:
DoCmd.OpenForm "frmReportFilter"

Then try clicking the Run button.
Does that fix it?
 

sja13

Professional Idiot
Local time
Today, 18:49
Joined
May 3, 2017
Messages
63
Tried removing acDialog, and got back to the original issue - the form is opened, but the VBA which opened it just keeps running (i.e. doesn't pause for the User to fill in the Form)
Code is definitely in the single click event.
I'll see if I can do some work at home later on, and also see if I can cleanse the Db of what the Boss deems sensitive and attach it (could be a bit of a big job).
 

missinglinq

AWF VIP
Local time
Today, 13:49
Joined
Jun 20, 2003
Messages
6,423
Not that Minty, most unusually, made an error! His

DoCmd.OpenForm "frmReportFilter", , , acDialog

has the acDialog in the wrong place...should have been

DoCmd.OpenForm "frmReportFilter", , , , , acDialog

Linq ;0)>
 

sja13

Professional Idiot
Local time
Today, 18:49
Joined
May 3, 2017
Messages
63
I'm sanitising the Db - when I'm done, do I post it as an attachment?
Is there any way to delete it from the post subsequently, when those people kind enough to help have examined it?
 

isladogs

MVP / VIP
Local time
Today, 18:49
Joined
Jan 14, 2017
Messages
18,261
@missinglinq
The OP put the acDialog in the wrong place & both Minty & I copied it in our replies .... oops

@sja13
Well you could delete the post after it completed but it would be better not to do so as others may learn from this thread at a later date.
Anyway one its been sanitised, why would you need to delete it?
 

sja13

Professional Idiot
Local time
Today, 18:49
Joined
May 3, 2017
Messages
63
OK guys - I fixed (???) the problem, but I'm not sure why it's fixed!

On various Forms there is a "List" Command Button.

Clicking this invokes a "standard" Sub "ListRequested", which issues the DoCmd.OpenForm command to show the Form frmListRequested.

The Form frmListRequested has a Command Button "Run".

When the "Run" button is clicked, after other code dealing with the User's choices has been executed, the form is dismissed from within the Command Button's VBA code.

For some reason using
Code:
  DoCmd.Close acForm, _
              Me.Name, _
              acSaveNo
or
Code:
  DoCmd.Close acForm, _
              Me.Name
perpetuates the problem, but
Code:
  DoCmd.Close
works!

My interpretation of the Microsoft Help for DoCmd.Close leads me to believe that the three options should do the same thing, but obviously I'm missing something.

Further investigation reveals that
Code:
  DoCmd.Close acDefault, _
              , _
              acSaveNo
also works "as expected".

Now I could just walk away with a smug "Problem Solved" grin, but in reality I'd be really grateful if someone could explain why my original code needed two single clicks of the Run button to work "as expected".

Any ideas guys?
 

Minty

AWF VIP
Local time
Today, 18:49
Joined
Jul 26, 2013
Messages
10,374
I'm back after some time away, I'd guess that the reference to Me.Name isn't actually referring to the current form.

You could prove it by adding a Debug.Print Me.Name before the code and see what it returns in the immediate window.
 

sja13

Professional Idiot
Local time
Today, 18:49
Joined
May 3, 2017
Messages
63
Hi Minty - hope you enjoyed your break!

The code to close the form is in the macro in the command button's click event on the form, and Debug.Print Me.Name does in fact give the name of the Form.

I've got a strong feeling that this is one of those "bump in the night" episodes.
I'm not sure "the spice is worth the ha'penny" as we say oop North.
The current code
Code:
  DoCmd.Close acDefault, _
              , _
              acSaveNo
still works, and although I'd love to find out why using the Form's name doesn't,
at my age (66) I'm not sure I want to spend a couple of years finding out!
 

Minty

AWF VIP
Local time
Today, 18:49
Joined
Jul 26, 2013
Messages
10,374
Well I tend to agree - all a bit strange but solved...
 

Users who are viewing this thread

Top Bottom