Solved

Not displaying some VBA SQL criteria

Posted on 2011-09-22
3
145 Views
Last Modified: 2012-05-12
Private Sub LBS(ocity As String, oprov As String, userinput As String)

  Dim sSQL As String, xcrit As String
   
    sSQL = "INSERT INTO [PROVINCE TO COUNTRY RATES] ([DESTIN CITY],"
    sSQL = sSQL & " [DESTIN PROVINCE], [MIN], LTL, 500, 1M, 2M, 5M, 10M, 20M)"
    sSQL = sSQL & " SELECT P2CSameTx65Table.[DESTIN CITY], P2CSameTx65Table.[DESTIN PROVINCE],"
    sSQL = sSQL & " P2CSameTx65Table.SERVICE, P2CSameTx65Table.Class, [P2CSameTx65Table]![MIN]+[getDestinBeyond]![MIN] AS [MIN],"
    sSQL = sSQL & " [P2CSameTx65Table]![LTL]+[getDestinBeyond]![LTL] AS LTL,"
    sSQL = sSQL & " [P2CSameTx65Table]![500]+[getDestinBeyond]![500] AS [500],"
    sSQL = sSQL & " [P2CSameTx65Table]![1M]+[getDestinBeyond]![1M] AS [1M],"
    sSQL = sSQL & " [P2CSameTx65Table]![2M]+[getDestinBeyond]![2M] AS [2M],"
    sSQL = sSQL & " [P2CSameTx65Table]![5M]+[getDestinBeyond]![5M] AS [5M],"
    sSQL = sSQL & " [P2CSameTx65Table]![10M]+[getDestinBeyond]![10M] AS [10M],"
    sSQL = sSQL & " [P2CSameTx65Table]![20M]+[getDestinBeyond]![20M] AS [20M]"
    sSQL = sSQL & " FROM getDestinBeyond INNER JOIN P2CSameTx65Table ON getDestinBeyond.[DESTIN CITY] = P2CSameTx65Table.[DESTIN CITY]"
    sSQL = sSQL & " WHERE [P2CSameTx65Table].TCOMBO =  [getDestinBeyond].[TCOMBI] & getDestinBeyond.[TCOMBI] "
    sSQL = sSQL & " AND getDestinBeyond.TCOMBI = " & Chr(34) & userinput & Chr(34) & " And P2CSameTx65Table.[Class] = " & [Forms]![Prov2Country]![classcombo] & ""
    
    sSQL = sSQL & " ORDER BY P2CSameTx65Table.[DESTIN CITY], P2CSameTx65Table.Class;"

    
    CurrentDb.Execute sSQL, dbFailOnError

End Sub

Open in new window


Hi,

I have the above function which apends to a table. Now I want it to sort using class and order using class but I do not want to display the 'Class' column (or hide it)

Could you please let me know how to do this via VBA?

Thanks!
0
Comment
Question by:Shanan212
3 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 400 total points
ID: 36582441
    sSQL = "INSERT INTO [PROVINCE TO COUNTRY RATES] ([DESTIN CITY],"
    sSQL = sSQL & " [DESTIN PROVINCE], [MIN], LTL, 500, 1M, 2M, 5M, 10M, 20M)"
    sSQL = sSQL & " SELECT P2CSameTx65Table.[DESTIN CITY], P2CSameTx65Table.[DESTIN PROVINCE],"
    sSQL = sSQL & " [P2CSameTx65Table]![MIN]+[getDestinBeyond]![MIN] AS [MIN],"
    sSQL = sSQL & " [P2CSameTx65Table]![LTL]+[getDestinBeyond]![LTL] AS LTL,"
    sSQL = sSQL & " [P2CSameTx65Table]![500]+[getDestinBeyond]![500] AS [500],"
    sSQL = sSQL & " [P2CSameTx65Table]![1M]+[getDestinBeyond]![1M] AS [1M],"
    sSQL = sSQL & " [P2CSameTx65Table]![2M]+[getDestinBeyond]![2M] AS [2M],"
    sSQL = sSQL & " [P2CSameTx65Table]![5M]+[getDestinBeyond]![5M] AS [5M],"
    sSQL = sSQL & " [P2CSameTx65Table]![10M]+[getDestinBeyond]![10M] AS [10M],"
    sSQL = sSQL & " [P2CSameTx65Table]![20M]+[getDestinBeyond]![20M] AS [20M]"
    sSQL = sSQL & " FROM getDestinBeyond INNER JOIN P2CSameTx65Table ON getDestinBeyond.[DESTIN CITY] = P2CSameTx65Table.[DESTIN CITY]"
    sSQL = sSQL & " WHERE [P2CSameTx65Table].TCOMBO =  [getDestinBeyond].[TCOMBI] & getDestinBeyond.[TCOMBI] "
    sSQL = sSQL & " AND getDestinBeyond.TCOMBI = " & Chr(34) & userinput & Chr(34) & " And P2CSameTx65Table.[Class] = " & [Forms]![Prov2Country]![classcombo] & ""
    
    sSQL = sSQL & " ORDER BY P2CSameTx65Table.[DESTIN CITY], P2CSameTx65Table.Class;"

Open in new window

0
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 100 total points
ID: 36582453
just remove the reference to P2CSameTx65Table.Class from line #8.

If you ONLY want to sort by class then change line 20 to:

    sSQL = sSQL & " ORDER BY P2CSameTx65Table.Class;"

0
 
LVL 13

Author Closing Comment

by:Shanan212
ID: 36582708
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now