Results 1 to 5 of 5
  1. #1
    Reg is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2014
    Posts
    1

    How to change the view (form / datasheet) of a subform with a macro?

    Hi there,



    I am not a real developer but I am also not totally new in Access 2013:

    Have a form with accounts and a subform with contacts and I have a button in the form where I want to change the view from the subform from form to datasheet or vice versa.

    Did not find any macro function for that.

    How do I do this?

    Thank you,

    R.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    I dont think you can swap subform layouts live. You would need 2 sub forms...1 shows a single form, and 2 to show datasheet view
    The button would have to re-assign what is in the subForm
    (this would be the best use of the Toggle button, rather than the regular command button)
    me.child0.form.sourceObject = "frmSingle"

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    What is the name of the form that is used as the subform control's Source Object? In your Main Form there is a subform container that holds another object. The subform has a Source Object property. In the source object property there, hopefully, is the name of a form object that you can locate within Access' Navigation Pane. for this discussion let's assume the name MyForm.

    Open that object in Design View and make sure that the Datasheet view and Single Form view properties are allowed.

    Then I would try these two options. It may not work because the default view may require the object to be open in Design or Edit mode.

    Forms!MainFormName!MyForm.DefaultView = "Single Form"

    or

    Forms!MainFormName!MyForm.DefaultView = "Datasheet"

    If that alone does not do the trick then try

    Me.SubformControlName.SourceObject = ""
    Forms!MainFormName!MyForm.DefaultView = "Datasheet"
    Me.SubformControlName.SourceObject = "MyForm"

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    I still cant get that to work ItsMe. I still get errors. Once you set SourceObject = ""
    There's no longer a form to set DEFAULT VIEW.

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by ranman256 View Post
    There's no longer a form to set DEFAULT VIEW.
    I did not test it so it may require additional code. My thought was remove the form from the equation by using SourceObject = "" and then employ the fully qualified Object name to talk to the form directly, no Me. shortcut.

    If the DefaultView is not available during Run Time then the form may need to be opened in edit mode, then adjust the properties, then save on close, then SourceObject = "MyForm"

    Or just have two objects, like you mentioned
    SourceObject = "MyForm"
    SourceObject = "MyForm2"
    Should work during Run Time

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-09-2013, 05:45 PM
  2. Replies: 3
    Last Post: 08-18-2013, 09:14 PM
  3. Replies: 6
    Last Post: 11-21-2012, 05:10 PM
  4. Change row-colors i subform datasheet view
    By rolfmagne in forum Forms
    Replies: 1
    Last Post: 03-02-2011, 11:07 AM
  5. Subform, Totals, in Datasheet view
    By eww in forum Programming
    Replies: 1
    Last Post: 09-27-2010, 10:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums