Form is opened but vba continues. (1 Viewer)

sja13

Professional Idiot
Local time
Today, 16:49
Joined
May 3, 2017
Messages
63
I have the following code snippet in a VBA module called "ListRequested".
Code:
 GoSub SetFiltersOnForm
  DoCmd.OpenForm ("frmReportFilter")
'  DoCmd.OpenForm "frmReportFilter", acNormal
  MsgBox "Back in ListRequested" & vbCrLf & _
         gstrWhere
  DoCmd.OpenReport strAllReport, _
                   acViewPreview, _
                   , _
                   gstrWhere
SetFiltersOnForm enables or disables textboxes on the Form frmReportFilter.
This works.

I am trying to use the Form frmReportFilter to allow the User to create a "Where" clause to be used in the Report.

When DoCmd.OpenForm is executed (as can be seen, I've tried different syntax on the OpenForm command.), the Form frmReportFilter is correctly formed and can be viewed in the background behind the MsgBox which is displayed immediately as the Form opens.

If I set a breakpoint at the DoCmd.OpenForm I can see that Form_Activate is invoked (it's empty).
I then get the MsgBox, and then go into DoCmd.OpenReport.

The problem is my Users don't have the chance to interact with the Form frmReportFilter.

It has the same properties as other forms which behave "correctly" (Modal=No, Pop Up=No, BorderStyle=Sizeable).

Perhaps I'm being dim here - the other Forms do what I expect them to do (they stay in focus and accept User interaction until I dismiss them via a DoCmd.Close statement behind a command button), but reading the Help on Modal and Pop Up suggests they shouldn't (at least to me!).

So I'm in a situation where Forms which apparently shouldn't wait for User input do, except for the one I'm working on now (frmReportFilter), which doesn't!

I've even tried setting frmReportFilter to Modal=True and Pop Up=True. This seems to have no effect! It's as if somewhere some other setting is overriding these properties.

Does anyone know of a "beginners guide to keeping the form in place until dismissed via a command button", or can they offer guidance.

Any help will be gratefully received....
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:49
Joined
May 7, 2009
Messages
19,246
put the messagebox on form frmReportFilter's UnLoad Event
therefore it will not show until the form is closed.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:49
Joined
Aug 30, 2003
Messages
36,133
In my experience, if the form is opened using the Dialog option in the window mode, code will stop and wait for the form to be closed or hidden.
 

sja13

Professional Idiot
Local time
Today, 16:49
Joined
May 3, 2017
Messages
63
arnelgp
The MsgBox is not necessary, it's only there to prove that as soon as the Form is displayed, the VBA continues without giving the User the chance to interact with the Form.

pbaldy
I've now tried making the form Border=Dialog, but it has no effect.
It seems very strange that the other forms in my application don't need to be Dialog (they're Sizable) to exhibit the "correct" behaviour.
However, this particular Form has no RecordSource. It holds a series of labels which indicate an Area, some associated Comboboxes which have a RowSource which is a "SELECT" statement offering the full contents of a standard Table, and textboxes which hold a condition.
The ideas is that a user can select for example
Label = Colour
Combobox = IS/IS NOT/CONTAINS/UNUSED
Textbox = 'text'
so the User can select Colour CONTAINS 'lue' to get a list containing "Blue" and "Gluey yellow"

Perhaps it's related to that in some way, 'cos all the other forms have a RecordSource whic is a Query.

I'll dig further......
 

Minty

AWF VIP
Local time
Today, 16:49
Joined
Jul 26, 2013
Messages
10,375
It's not making the border Dialog - it's openeing the form as a Dialog that's important.

Code:
DoCmd.OpenForm FormName:="Customer", View:=acNormal,DataMode:=acFormPropertySettings, [B][COLOR="Red"]WindowMode:=acDialog[/COLOR][/B]
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:49
Joined
Aug 30, 2003
Messages
36,133
I'll get out of the way.
 

Minty

AWF VIP
Local time
Today, 16:49
Joined
Jul 26, 2013
Messages
10,375
No need Paul - just looked like you were off line - standing down...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:49
Joined
May 7, 2009
Messages
19,246
so no need for message box.
then put also the opening of the report the the Unload event
of form frmReportFilter.
 

sja13

Professional Idiot
Local time
Today, 16:49
Joined
May 3, 2017
Messages
63
Hey Paul and Minty - if I've said anything wrong, please accept my apologies. There's no need to stand down. It's fairly obvious I need all the help I can get!

Minty - if you're still around, is that setting available on the Property sheet?
I'm having difficulty finding it, which could be because I'm genuinely registered as blind, and am also probably certifiable!
 

Minty

AWF VIP
Local time
Today, 16:49
Joined
Jul 26, 2013
Messages
10,375
No I don't think it is on the property sheet, you can right click the form icon from the navigation window and open it as dialog.

To be fair it's not a way you would default a form to open - I think you would only ever do this from Code.
 

sja13

Professional Idiot
Local time
Today, 16:49
Joined
May 3, 2017
Messages
63
Thanks guys - now I can start solving my other (numerous) problems.
Minty - works fine from VBA! Just what was needed!
 

Users who are viewing this thread

Top Bottom