Results 1 to 11 of 11
  1. #1
    StampMan is offline Novice
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Perth, Western Australia
    Posts
    24

    Opening Forms In Specific Order

    Hi,
    How can I change the order that my forms open in? I do NOT want to change my table primary key (Record Number) but I want my form to open in the order that is set by another unique field. So, rather than the forms opening in record number sequence they would open up in the sequence set by this other field in the table. I'm sure that I've achieved this before but can't remember how or where. Any advice greatly appreciated. :-)

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You control the form open order.
    the last one you open will be on 'top' where the user sees.

    use autoexec macro to open the forms in the order you want.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Are you referring to sorting the records by descending order or sorting records by descending order? This can be accomplished with a Query Object. Bind your form to a Query and manage sorting in the Query.

  4. #4
    StampMan is offline Novice
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Perth, Western Australia
    Posts
    24
    I thought there was something along the lines of either "OrderBy" or "SortBy" somewhere in the forms property fields (when in design mode of course). I just want them to appear in ascending order but not by the record number (primary key) but by another field.????

  5. #5
    StampMan is offline Novice
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Perth, Western Australia
    Posts
    24
    Thanks guys................... Found the property I needed to change to achieve this. :-)

    Oooops.................... still having problems. :-(
    Last edited by StampMan; 10-08-2015 at 11:19 AM. Reason: Jumped the Gun!

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    There are properties in the form that can achieve this. I find it easier to do it in the query. I suggest using one approach, consistently. Otherwise, it may not be perfectly understandable why your application behaves a particular way.

  7. #7
    StampMan is offline Novice
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Perth, Western Australia
    Posts
    24
    Quote Originally Posted by ItsMe View Post
    There are properties in the form that can achieve this. I find it easier to do it in the query. I suggest using one approach, consistently. Otherwise, it may not be perfectly understandable why your application behaves a particular way.
    Hmmmmm, I see what you are saying. I've now encountered another problem. The forms now open in the order I want but with a numerical glitch. The field I want to sort my forms by is called 'UniqueCode'
    It's a combination of letters and numbers, e.g. CGBQ-1024
    But the sort order now comes out in this format....

    CGBQ-112
    GGBQ-1024
    CGBQ-206
    CGBQ-287
    CGBQ-2113

    See how it's sorting by fields with 1's first before moving onto 2's for example. CGBQ-1024 should come after 206 and 287 because it's a higher numerical value (thousands instead of hundreds) a proper sort would look like......

    CGBQ-112
    CGBQ-206
    CGBQ-287
    CGBQ-1024
    CGBQ-2113

    I wouldn't even know how to create or apply a query to remedy this............... Please help :-)

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    What you need to do is create an alias in a query. This alias will create a virtual column within your query. The alias will be the number part of your original field. For instance, the original field will have a Value of CGBQ-112 and the alias would have a value of 112.
    Code:
    MyAlias: Mid(FieldName, InStrRev(FieldName, "-") + 1)
    You would type something like this in a new field in your query via the query designer. This new field will be the second column to receive a sort order. There are some additional steps that need to be taken in order for your main objective to be met. However, start by creating a query and an alias.

  9. #9
    StampMan is offline Novice
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Perth, Western Australia
    Posts
    24
    Thank you, but,
    It's official.................. I'm lost :/

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    You need to create something that will look at the letters and the numbers independently. A query can do this for you. It will manage it logically. You do not need to worry about why you would separate them. In the end, they will be put back together.

    Start by creating a Query. Within the Ribbon and under the Create tab, click 'Query Design'. Add your Table(s). Create a SELECT query by bringing the desired fields into the grid at the bottom of the designer window. After that, create an additional column via copy paste. Use the code I provided in post #8. The only difference is you need to replace the text in red with the name of the field/column. Use the name of the column that has stuff like CGBQ-112 in it.
    Click image for larger version. 

Name:	QueryGrid.jpg 
Views:	9 
Size:	44.4 KB 
ID:	22350

    Go ahead and save your query. Now, you need to add some stuff so the query knows how to sort the data it retrieves. Go to your field, as it is represented within the grid, that contains the stuff with CGBQ-112 in it. In the row that is labeled 'Sort', use the pulldown to select 'Ascending'. SAVE your query.
    Click image for larger version. 

Name:	QuerySort.jpg 
Views:	9 
Size:	40.5 KB 
ID:	22351
    Now, you can add a second request to sort by ascending. Do this in your Alias column you created when you pasted the code from post #8. Select Ascending from the pulldown provided within your Alias column. SAVE your query.

    Now when you view your query via the View button under the Home tab of the Ribbon or by double clicking the Query from within the Navigation Pane, the sorting should work in the desired way.

    Use your new query as the recordsource of your form.

  11. #11
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I went ahead and tested the example I posted in post #10. Go ahead and go through that example. Afterwards, you will need to make a couple of adjustments.

    You will need to create two alias'. I thought it might work with only one, but it does not. Also, the code in post #8 needs some additional stuff that will tell Access we are dealing with a number and not text.

    So here are code examples for the two alias'
    Code:
    MyAlias: CInt(Mid([FieldName],InStrRev([FieldName],"-")+1))
    
    MyTextAlias: Left([FieldName],InStrRev([FieldName],"-")-1)
    With that, you will want to sort MyTextAlias first and sort MyAlias second. The priority will go on MyTextAlias. To do this, make sure you add MyTextAlias first. It should appear to the left of MyAlias.

    As I said, go ahead and work through post #10 to get the alias thing under your belt. Then we can work on it together to fine tune it. I am attaching an example of a working query using two alias'.
    Attached Files Attached Files

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

Similar Threads

  1. Replies: 3
    Last Post: 06-09-2015, 09:19 AM
  2. Replies: 5
    Last Post: 01-24-2015, 12:59 AM
  3. Replies: 2
    Last Post: 06-17-2014, 09:15 AM
  4. Why is my form opening in alphabetical order?
    By Access_Novice in forum Forms
    Replies: 6
    Last Post: 12-10-2013, 05:22 PM
  5. Replies: 11
    Last Post: 07-08-2011, 02:12 PM

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