Results 1 to 4 of 4
  1. #1
    bell is offline Advanced Beginner
    Windows 7 64bit Access 2002
    Join Date
    Feb 2015
    Posts
    37

    Question Having problems using OrderBy property after DoCmd.OpenForm

    Hi All,



    I am doing something wrong, and I cant figure it out

    I have a form "Wirelist Cover Form", and I use a button click to open another form "Wirelist Form" as so

    stDocName = "Wirelist Form"
    stLinkCriteria = "[Document Number] = '" & Me![Document Number] & "'" & " AND [Revision] = '" & Me![Revision] & "'"
    DoCmd.Close acForm, "Wirelist Cover Form"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Now, I want to order the "Wirelist Form" by the field "Wire" because I have noticed that sometimes the wires do not show up in order.

    One problem is, the "Wirelist Form" has a subform "Wirelist subform" where the wires are actually displayed.

    Now, I thought I could use the OrderBy property after using the Open Form like

    Forms![Wirelist Form]![Wirelist subform].OrderBy = "[Wire]"
    Forms![Wirelist Form]![Wirelist subform].OrderByOn = True

    But I get the error "Object doesn't support this property or method"

    Can someone help me figure out what the correct way is to sort these wires?

  2. #2
    bell is offline Advanced Beginner
    Windows 7 64bit Access 2002
    Join Date
    Feb 2015
    Posts
    37
    Well nevermind, I instead used the subforms Open event to do

    Me.OrderBy = "[Wire]"
    Me.OrderByOn = True

    Still a little confused why my other code wouldnt work, but I guess it doesnt matter now

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Glad you got it to work.

    Subforms are not part of the Forms! collection, even when they are open, so you cannot refer to them that way. (Forms![Wirelist Form]![Wirelist subform].OrderBy = "[Wire]").

    What you have to do is use the name of the subform container control on the main form, and then refer to the subform within it. For example, let's assume you names the subform control (on the main form) sfrmContainer.

    Your expressions would now look like this:

    Forms![Wirelist Form]![sfrmContainer].form.OrderBy = "[Wire]"
    Forms![Wirelist Form]![sfrmContainer].form.OrderByOn = True

  4. #4
    bell is offline Advanced Beginner
    Windows 7 64bit Access 2002
    Join Date
    Feb 2015
    Posts
    37
    Quote Originally Posted by John_G View Post
    Glad you got it to work.

    Subforms are not part of the Forms! collection, even when they are open, so you cannot refer to them that way. (Forms![Wirelist Form]![Wirelist subform].OrderBy = "[Wire]").

    What you have to do is use the name of the subform container control on the main form, and then refer to the subform within it. For example, let's assume you names the subform control (on the main form) sfrmContainer.

    Your expressions would now look like this:

    Forms![Wirelist Form]![sfrmContainer].form.OrderBy = "[Wire]"
    Forms![Wirelist Form]![sfrmContainer].form.OrderByOn = True
    Ohh okay thank you!

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

Similar Threads

  1. Docmd.openform (date) and (text)
    By sovereign in forum Forms
    Replies: 3
    Last Post: 06-19-2015, 08:07 AM
  2. DoCmd.OpenForm; 3rd Argument = FilterName
    By Access_Novice in forum Programming
    Replies: 1
    Last Post: 02-02-2014, 11:05 PM
  3. DoCmd.OpenForm Syntax Error
    By alsoto in forum Forms
    Replies: 3
    Last Post: 02-29-2012, 01:14 PM
  4. What actually happens at docmd.openform
    By Beorn in forum Programming
    Replies: 4
    Last Post: 01-05-2011, 02:19 PM
  5. DoCmd.OpenForm Modification
    By alsoto in forum Forms
    Replies: 6
    Last Post: 05-01-2009, 07:28 AM

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