Results 1 to 5 of 5
  1. #1
    bharatkk is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2017
    Location
    Pune, India
    Posts
    9

    Access query from Northwind database

    Hi all,

    I am not sure how significant this question is but I am posting this all the same because I am very baffled by it. Following is a modified sql statement

    Code:
    SELECT IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[Company],[First Name]),IIf(IsNull([First Name]),[Last Name],[Last Name] & ", " & [First Name])) AS [File As], 
    
    
    IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[Company],[First Name]),IIf(IsNull([First Name]),[Last Name],[First Name] & " " & [Last Name])) AS [Contact Name]
    
    
    FROM Customers
    As per my understanding when the query is run their should appear two field 1) "File As" and 2) "Contact name" and in this order. What baffles me is that instead on File As appearing as first field it appears 2nd after "Contact Name" but actually "Contact Name" field appears first and then "File As".

    I thought may be this is because alphabetically "C" comes before "F" but when I changed it to anything else "File As" field comes first and then the other field. I have even tried just "A" with same consequence i.e. "File As" field appears first and then "A".



    Am I making any sense ? Could anyone please help me clear this confusion ?

    By the way the code I posted in one single query. I have broken them in different lines for readability.

    Thanks & regards everybody,

    Bharat

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I built query using those alias names and cannot replicate this. [File As] comes before [Contact Name].
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    bharatkk is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2017
    Location
    Pune, India
    Posts
    9
    Hello,

    Thanks for your response. I am inserting screen shot for your reference :
    Click image for larger version. 

Name:	Query Screenshot.jpg 
Views:	17 
Size:	135.7 KB 
ID:	28632Click image for larger version. 

Name:	Output Screenshot.jpg 
Views:	16 
Size:	174.2 KB 
ID:	28633

    Thanks & regards,

    Bharat

    Quote Originally Posted by June7 View Post
    I built query using those alias names and cannot replicate this. [File As] comes before [Contact Name].

  4. #4
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    In that the design view order and datasheetview order are not the same, it implies the fields were re-arranged at some point and the view was saved in that state. While in datasheetview you can order the columns any way you want, close it, and you will be prompted to save the layout.

    You could also reset the order as seen in design view:
    Code:
    Public Sub ResetColumnOrder(strQueryName)
    
        Dim fld As DAO.Field
        Dim qdf As DAO.QueryDef
    
        Set qdf = CurrentDb.QueryDefs(strQueryName)
    
        For Each fld In qdf.Fields
            On Error Resume Next
            fld.Properties.Delete "ColumnOrder"
        Next fld
    
    End Sub

  5. #5
    bharatkk is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2017
    Location
    Pune, India
    Posts
    9
    Hello!

    Thanks for your response. Based on your suggestion I reset the order and it worked.

    Quote Originally Posted by jwhite View Post
    In that the design view order and datasheetview order are not the same, it implies the fields were re-arranged at some point and the view was saved in that state. While in datasheetview you can order the columns any way you want, close it, and you will be prompted to save the layout.

    You could also reset the order as seen in design view:
    Code:
    Public Sub ResetColumnOrder(strQueryName)
    
        Dim fld As DAO.Field
        Dim qdf As DAO.QueryDef
    
        Set qdf = CurrentDb.QueryDefs(strQueryName)
    
        For Each fld In qdf.Fields
            On Error Resume Next
            fld.Properties.Delete "ColumnOrder"
        Next fld
    
    End Sub
    Thanks once again.

    Bharat

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

Similar Threads

  1. Northwind access database help
    By ianhaney28 in forum Access
    Replies: 1
    Last Post: 03-28-2014, 11:48 AM
  2. Access 2003 Northwind Sample Database
    By Troop in forum Access
    Replies: 2
    Last Post: 05-18-2013, 10:50 PM
  3. Northwind Database Question....
    By DarrenUD in forum Access
    Replies: 1
    Last Post: 02-25-2013, 01:47 AM
  4. Help with Database from Northwind
    By jpl85716 in forum Access
    Replies: 2
    Last Post: 09-24-2010, 08:35 AM
  5. Northwind sample database query
    By wasim_sono in forum Programming
    Replies: 5
    Last Post: 02-28-2006, 07:34 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