Order by sql

silentwolf

Well-known Member
Joined
May 14, 2008
Messages
1,216
Office Version
  1. 2016
Hi guys,

can't seam to get this right.

Here is my code and it works fine... however I would like to ORDER objMDatum in DESC order..
Unfortunatelly I have not been able to get it right .. Can someone help with this please?

Code:
Private Sub Form_Current()
    Dim strSQL As String
    
    strSQL = "SELECT objMID, objMDatum, objMAnfang, objMEnde, objMPause, objMObjIDRef " & _
    "FROM tblObjMitarbeiter WHERE objMObjIDRef= " & Me!objID
   
    Me!lstObjektStunden.RowSource = strSQL

End Sub

oh Sorry this is in the wrong forum! It s Access...
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try:
Code:
    strSQL = "SELECT objMID, objMDatum, objMAnfang, objMEnde, objMPause, objMObjIDRef " & _
    "FROM tblObjMitarbeiter WHERE objMObjIDRef= " & Me!objID & _
    " ORDER BY [COLOR=#574123]objMDatum DESC";[/COLOR]
 
Upvote 0
Hi Joe4,
thanks for your reply!
Unfortunatelly this is not working :(
Code:
    strSQL = "SELECT objMID, objMDatum, objMAnfang, objMEnde, objMPause, objMObjIDRef " & _
    "FROM tblObjMitarbeiter WHERE objMObjIDRef= " & Me!objID & _
    " ORDER BY [COLOR=#574123]objMDatum DESC"[/COLOR]

The last semicolumn gives a syntax error but when I leave it out like above no records are displayed at all..
 
Upvote 0
the ORDER BY won't stop you getting records

the syntax is

SELECT
FROM
WHERE
ORDER BY

test the SELECT FROM then build from there
 
Upvote 0
Hi mole999,
sorry I don't really understand what you mean.
Without to ORDER BY it gives me the right filter back but as soon I put the ORDER BY into the statement no records are displayed
 
Upvote 0
Hi Joe4,
thanks for your reply!
Unfortunatelly this is not working :(
Code:
    strSQL = "SELECT objMID, objMDatum, objMAnfang, objMEnde, objMPause, objMObjIDRef " & _
    "FROM tblObjMitarbeiter WHERE objMObjIDRef= " & Me!objID & _
    " ORDER BY [COLOR=#574123]objMDatum DESC"[/COLOR]

The last semicolumn gives a syntax error but when I leave it out like above no records are displayed at all..


there is NO semicolon in that code
 
Upvote 0
Sorry, in my original reply I had:
Code:
    " ORDER BY [COLOR=#574123]objMDatum DESC";[/COLOR]

The semi-colon usually goes inside the quotes, i.e.
Code:
    " ORDER BY [COLOR=#574123]objMDatum DESC;"[/COLOR]
but it usually isn't necessary at all (you can usually just take it or leave it).

But an "Order By" does not do anything to filter records. If it is showing no data, then it is probably your part of the code that isn't working right.
 
Upvote 0
What is the value in ObjID? Is that somehow messing up the SQL statement when you have an ORDER BY clause after the WHERE?

Hi mole999,
sorry I don't really understand what you mean.
Without to ORDER BY it gives me the right filter back but as soon I put the ORDER BY into the statement no records are displayed
 
Upvote 0
Hi guys,
thanks for replying! Unfortunatelly I can not check it today but will keep you posted on how I am going!
 
Upvote 0

Forum statistics

Threads
1,221,783
Messages
6,161,913
Members
451,730
Latest member
BudgetGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top