Changing Form's view in VBA

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RLN

    Changing Form's view in VBA


    I have a form that does not display correctly.
    frm1 opens frm2 via a command button.

    My three problems with frm2:
    1. Displays in form view when called from the button.
    (should be datasheet view)
    2. "Shortcut Menu" is set to "Yes", however I cannot right click in the
    form to go to design view.

    These properties are already set on frm2:
    "Shortcut Menu is set to "Yes"
    View is set to "Datasheet view" by default.
    "Allow pivot view", and "allow form view" are both set to "no.

    Here is my code that launches frm2:

    strSQL1 = "Select Field1, Field2 FROM tblX"

    'open the form
    DoCmd.OpenForm "frm2"

    Forms!frmCurren tBatches.Record Source = strSQL1

    Forms!frmCurren tBatches.Refres h
    Forms!frmCurren tBatches.Visibl e = True

    - - - - - - -
    'When trying to set the view to datasheet,these 2 lines did not work...
    'Forms!frmCurre ntBatches.Defau ltView = 2
    ' DoCmd.OpenForm FormName:=frm2, View:=acFormDS

    Finally, I need to disallow the user the opportunity to right click on
    any form they have loaded. I don't want them to have the opportunity to
    get to design mode.
    Is there a simple way to set the 'allow shortcut menu' property to "no"
    on all of the forms when the app loads, then set that property on all
    forms back to "yes" when the app closes?

    Any suggestions would be helpful.

    Thnx.....



    *** Sent via Developersdex http://www.developersdex.com ***
  • Linq Adams via AccessMonster.com

    #2
    Re: Changing Form's view in VBA

    Here's the answer to Problem # 1

    When calling one form from another form, you have to explicitly call it in
    Datasheet View by using the View parameter, acFormDS. This has to be done
    regardless of the default view that's set for the form.

    DoCmd.OpenForm "frm2", acFormDS

    Good luck in finding answers to the rest of your questions!

    --
    There's ALWAYS more than one way to skin a cat!

    Answers/posts based on Access 2000/2003

    Message posted via AccessMonster.c om


    Comment

    • Allen Browne

      #3
      Re: Changing Form's view in VBA

      Linq Adams gave you the answer to #1, so let's look at #2.

      What version of Access is this?
      If A2007, and this is a subform, get the April 11 hotfix:


      I didn't follow the last part: seems like you want to right-click on the
      form, not be able to right-click on the form.

      Perhaps you could create an MDE (or ACCDE) for your users. They won't be
      able to switch to design view for forms, reports, or code.

      --
      Allen Browne - Microsoft MVP. Perth, Western Australia
      Tips for Access users - http://allenbrowne.com/tips.html
      Reply to group, rather than allenbrowne at mvps dot org.

      "RLN" <nospamrln@devd ex.comwrote in message
      news:1214341261 _11464@news.new sfeeds.com...
      >
      I have a form that does not display correctly.
      frm1 opens frm2 via a command button.
      >
      My three problems with frm2:
      1. Displays in form view when called from the button.
      (should be datasheet view)
      2. "Shortcut Menu" is set to "Yes", however I cannot right click in the
      form to go to design view.
      >
      These properties are already set on frm2:
      "Shortcut Menu is set to "Yes"
      View is set to "Datasheet view" by default.
      "Allow pivot view", and "allow form view" are both set to "no.
      >
      Here is my code that launches frm2:
      >
      strSQL1 = "Select Field1, Field2 FROM tblX"
      >
      'open the form
      DoCmd.OpenForm "frm2"
      >
      Forms!frmCurren tBatches.Record Source = strSQL1
      >
      Forms!frmCurren tBatches.Refres h
      Forms!frmCurren tBatches.Visibl e = True
      >
      - - - - - - -
      'When trying to set the view to datasheet,these 2 lines did not work...
      'Forms!frmCurre ntBatches.Defau ltView = 2
      ' DoCmd.OpenForm FormName:=frm2, View:=acFormDS
      >
      Finally, I need to disallow the user the opportunity to right click on
      any form they have loaded. I don't want them to have the opportunity to
      get to design mode.
      Is there a simple way to set the 'allow shortcut menu' property to "no"
      on all of the forms when the app loads, then set that property on all
      forms back to "yes" when the app closes?

      Comment

      • RLN

        #4
        Re: Changing Form's view in VBA



        Yes, Linq's solution worked.
        Looks like the MDE might be the way to go.
        I have never deployed MDE's before. Are there any known 'gotchas' to
        watch for when building the MDE (aside from making sufficient backups of
        the .mdb)?
        I can search MSDN/TEchNet for that answer, but I just wondered if there
        were others not listed that you may have encountered.

        Thanks,
        RLN

        *** Sent via Developersdex http://www.developersdex.com ***

        Comment

        • Allen Browne

          #5
          Re: Changing Form's view in VBA

          MDEs are quite easy: give it a shot.
          Because you retain your MDB, you are not easily snookered.

          The main 'gotchas' have to do with running across different versions of
          Access, or on different computers. You can only create an MDE using the
          version for the file format. For example, Access 2002, 2003, and 2007 can
          create an MDB in A2000 format, but only A2000 can create the MDE. The later
          versions can use the A2000 MDE: they just can't create it.

          A2002 and 2003 share the same file format, so you do need to watch the
          versions there. If you create an MDE in this file format in A2003, you
          cannnot use it in A2002. But create it in A2002, and you can use it in the
          later versions.

          If your MDE will be used on other computers too, be careful about the
          library references. Your MDE won't work if the other computers lack the
          library you used, or if they have a different version of the library.

          In general, therefore, you want to keep to the minimal references: typically
          VBA, Access and DAO. Access will automatically sort these out across
          versions (from 2000 to 2007.)

          More info on references:
          How to identify and solve problems with VBA references in a Microsoft Access database. Includes a listing of the libraries needed for each version of Access.


          --
          Allen Browne - Microsoft MVP. Perth, Western Australia
          Tips for Access users - http://allenbrowne.com/tips.html
          Reply to group, rather than allenbrowne at mvps dot org.

          "RLN" <nospamrln@devd ex.comwrote in message
          news:1214516634 _15109@news.new sfeeds.com...
          >
          Yes, Linq's solution worked.
          Looks like the MDE might be the way to go.
          I have never deployed MDE's before. Are there any known 'gotchas' to
          watch for when building the MDE (aside from making sufficient backups of
          the .mdb)?
          I can search MSDN/TEchNet for that answer, but I just wondered if there
          were others not listed that you may have encountered.

          Comment

          Working...