Share via

OpenForm Data Mode and Window Mode

Anonymous
2011-11-05T02:20:39+00:00

I am using Microsoft Access 2010 and trying to create a Command Button that opens a form in Data Mode Add and Window Mode Dialog.

I added the Command Button to a blank form and added the OpenForm function to the On Click event, setting the Form Name, Data Mode to Add and Window Mode to Dialog.

I then changed the view to Form View and tried clicking my new button...

The form appeared, but it was not a dialog, it was a separate tab, and it wasn't in Add mode - it was displaying the first record in the underlying table and allowed me to edit that record.

After a little experimentation, I learned that the button was merely bringing the already open form to the foreground (so to speak - excuse me if this isn't the usual terminology) in whatever mode it was already in. If I closed the form then pressed the button again, the form was re-opened in Dialog mode with blank fields.

My question is: how can I make a command button that opens a form in Add mode as a Dialog, regardless of whether the form is already open, and without disturbing any instances of the form that are already open?

Thanks,

Ian

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2011-11-07T02:37:30+00:00

Thanks for the detailed background; it puts your questions into context.  Let's look at a few specific points.

<QUOTE>

This final screen should be "full screen" and could be modal, though there is no need for it to be a pop-up window and, I suspect, might make best use of limited tablet screen realestate if it were a regular window rather than a pop-up window.

</QUOTE>

It seems to me that you don't in fact want dialog mode.  Modal would work for you, or you could present a form that occupies the whole Access window (which may or may not be full-screen, as you choose), and can only be closed by making a selection or clicking a Cancel button. 

<QUOTE>

In this particular instance, I don't think I need to deal with multiple instances of a form being open.

</QUOTE>

I agree; from your description, I don't see why you would need multiple instances of the same form.  I've used that technique in applications where one wants to see multiple related entities of the same type together, as for example an employee and his supervisor, or a school child and each of his parents.  But so far as I can see, your application drills down to a single specific question, then displays it -- one question at a time.

<QUOTE>

I don't even know if it is practical / possible to have multiple instances of a form open at the same time in Access, but I have done so in other application frameworks and, if it is possible, I would like to know how to do it in Access and, as much as possible write my applications to open forms in a way that is independent of whether or not there are any instances of the form already open.

</QUOTE>

It is both possible and practical, under the right conditions, though you have to manage the forms yourself.  However, you mention using SharePoint and web deployment, and I don't think you can do it with Access web forms.  I could be wrong, but the only way I know of to do it involves forms with VBA code behind them, and Access web forms can't have VBA code, so that method won't work.

Since you asked, the non-web method for opening multiple instances of an Access form only works for form's with VBA code, because forms with VBA have class modules, and you can create what is called a non-default instance of the form -- or any number of such instances -- by using VBA to create a new instances of that class module, as with code similar to this:

    Dim frm As Form_MyFormName

    Set frm = New Form_MyFormName

    frm.Visible = True

The form instance will close automatically and be destroyed when the last refernce to the class instance goes out of scope.  This generally means that you need to maintain a global collection of form references, adding each new instance to the collection when you create it, and removing the reference from the collection when you want to close the form or when you detect that the user has closed it.

To locate a specific instance from among several, you could either assign a specific key to each instance when you add it to the collection, or else loop through the collection members checking properties of each instance, such as the .Caption property, until you find the one you want.

Unfortunately, as I said, this method creating multiple instances won't work with Access web forms.  If there's another method that you could use with web forms, I don't know about it, but I haven't yet spent any time working with the new web features of Access 2010.

As for writing your application "to open forms in a way that is independent of whether or not there are any instances of the form already open", I'm not sure that it's worth stepping outside of the built-in functionality of Access unless you really want to allow multiple instances of the same form open.  Access assumes that, if you say "open form X" and form X is already open, all you want to do is bring form X to the front.  However, you can easily write your own form-opening routine that determines whether the form you requested is already open, and if it is, does whatever you want to it:  close and reopen, or filter to a different record, or set various properties, or whatever.  It's simple to tell if form X is already open;  just write:

    If CurrentProject.AllForms("X").IsLoaded Then

If you need to determine what "view" the form is open in, you can check properties of the form for that.

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2011-11-07T03:27:44+00:00

    Hi Dirk,

    Your response is much appreciated. The picture is coming clearer now and your confirmation of my suspicions and further guidance really help.

    I will put aside unnecessary complications (multiple form instances) for another day. I suspect, as you do, that it is difficult or impossible in Access Web.

    The issue of the form being open with I "OpenForm" remains. For example, in my test I had OpenForm open the form for add but, because the form was already open an entirely different interface was presented, allowing any record to be edited and not focused on the Add task. Easy enough for me to deal with, but maybe not so easy for one of our users.

    For this issue, rather than changing how we open forms, maybe I'll concentrate on ensuring forms aren't left open inappropriately. If the user is opening forms manually in a full Access client, I will maybe have to rely on them being sophisticated enough to know what to do.

    Ian

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-11-05T21:42:39+00:00

    Hi Dirk,

    This is all quite new to me - lots of new terminology that I may often use more or less incorrectly - it is quite appropriate that you question whether I want "dialog mode". Actually, I don't want dialog mode specifically. Effectively, the application presents a questionnaire, divided into sections. There will be a cascade of selectors (combo boxes, list boxes or similar - the style is not yet determined exactly) with some context details presented as one descends through the cascade. Near the bottom will be a list of questions relevant to the particular context, with the option to cycle through the list or jump to any particular question. Ultimately, a single question will be presented, with various inputs, depending on the nature of the question. This final screen should be "full screen" and could be modal, though there is no need for it to be a pop-up window and, I suspect, might make best use of limited tablet screen realestate if it were a regular window rather than a pop-up window.

    In this particular instance, I don't think I need to deal with multiple instances of a form being open. I stumbled what OpenForm does when the form is already open by accident, as I had the form open to develop it. I don't even know if it is practical / possible to have multiple instances of a form open at the same time in Access, but I have done so in other application frameworks and, if it is possible, I would like to know how to do it in Access and, as much as possible write my applications to open forms in a way that is independent of whether or not there are any instances of the form already open. If multiple instances can be open at the same time, I would also like to know how to refer to a particular instance and return the focus to that instance.

    I am at an early stage of learning Access and developing this application. The application already exists on another platform and we are considering migrating to Access 2010 / Sharepoint for web deployment. While it would be good to know if we can achieve the same look and feel as the current implementation, this is not necessary. We can change it to make best use of the abilities of Access / Sharepoint, as long as the business requirements are satisfied. So, with regard to your questions, we could go various ways in every case.

    I don't want to get into essoteric programming at this point - I want to learn to make best use of core, common functionality. My approach to problems may be at odds with the capabilities and limitations of Access, and I may have to adapt how I try to solve them. If the solutions are not cost effective to develop and maintian, they are of no use to me, and we have very tight budgets, so need to keep things simple.

    This is a long and vague answer to your questions, but maybe a basis for you to give some further guidance.

    You said "this isn't hard to do". I would be very appreciative if you could provide pointers to documentation or examples of how to handle multiple instances of a form.

    Regards,

    Ian

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2011-11-05T13:01:45+00:00

    I am using Microsoft Access 2010 and trying to create a Command Button that opens a form in Data Mode Add and Window Mode Dialog.

    I added the Command Button to a blank form and added the OpenForm function to the On Click event, setting the Form Name, Data Mode to Add and Window Mode to Dialog.

    I then changed the view to Form View and tried clicking my new button...

    The form appeared, but it was not a dialog, it was a separate tab, and it wasn't in Add mode - it was displaying the first record in the underlying table and allowed me to edit that record.

    After a little experimentation, I learned that the button was merely bringing the already open form to the foreground (so to speak - excuse me if this isn't the usual terminology) in whatever mode it was already in. If I closed the form then pressed the button again, the form was re-opened in Dialog mode with blank fields.

    My question is: how can I make a command button that opens a form in Add mode as a Dialog, regardless of whether the form is already open, and without disturbing any instances of the form that are already open?

     

    Your last requirement,"without disturbing any instances of the form that are already open", is the tricky bit.  If you want to have multiple instances of your form open at once, you're going to need to go beyond the normal Access form-handling methods.  This isn't hard to do, except for the additional requirement that at least the new instance be opened in dialog mode.  That may be harder to implement.

    Before chasing down this path, can we establish the bigger picture of how this form is going to be used in your application?  Will all instances of the form need to be opened the same way, in dialog mode?  Do you really mean dialog mode, not just popup or windowed mode -- dialog mode being a special mode in which the focus can't leave the form and all calling code is halted until the form is closed or hidden.  Are you going to have a mix of default (opened by OpenForm) and non-default instances of your form?

    Was this answer helpful?

    0 comments No comments