20. januar 2003 - 08:14Der er
22 kommentarer og 1 løsning
ORDER BY syntax
Hej
Jeg prøver lige igen.
Jeg har en forespørgsel, hvor jeg gerne vil have mulighed på at sorterer efter værdien i en COMBO på en formular. Jeg har problemder med at få mit ORDER BY statement til at fungerer. Jeg har forsøgt at bruge Like med da det jo er feltnavnet på det felt jeg ønsker at sortere på jeg skal sætte ind virker det ikke. Jeg har også prøvet med forskellinge kombinationer af ' og " med samme resultat. Det må da kunne lade sig gøre!
Koden herunder er det seneste forsøg...
mvh René
SELECT TAB_genstand.Hovedkategori, TAB_genstand.Underkategori, TAB_genstand.Navn, TAB_genstand.[Sikkerheds foreskrifter], TAB_genstand.Uddannelsekrav, TAB_genstand.Bemærkninger, TAB_genstand.Ydelse, TAB_genstand.Enhed1, TAB_genstand.Strømforbrug, TAB_genstand.Enhed5, TAB_genstand.Strømforsyning, TAB_genstand.Drivmiddel, TAB_genstand.Diverse, TAB_genstand.Placering, TAB_genstand.Antal, TAB_genstand.Pakning FROM TAB_genstand WHERE (((TAB_genstand.Hovedkategori) Like IIf([Formularer]![FORM_start]![COMBO_soeg_hoved]="Alle"," ",[Formularer]![FORM_start]![COMBO_soeg_hoved])) AND ((TAB_genstand.Underkategori) Like IIf([Formularer]![FORM_start]![COMBO_soeg_under]="Alle"," ",[Formularer]![FORM_start]![COMBO_soeg_under])))
ORDER BY [TAB_genstand].Formularer!FORM_soeg!COMBO_soeg_sortering DESC;
Så får jeg en dialogboks der beder mig definerer værdien af TAB_genstand.Formu.... og selv om jeg så der taster en valid værdi bliver den ikke sat ind.
Din sorteringsrækkefølge vil gå på et feltnavn, ikke på indholdet af et felt. Jeg kan sagtens tage fejl, men jeg mener ikke at du umiddelbart kan have et variabelt sorteringskriterium.
rene..>In the query builder you can use the expression builder wizard to help you. First open the form which you want to use in the query. Then open the query. Place the mouse cursor in an empty field (where you normally choose a field from the table). Now right click with the mouse. You will see a build icon, choose this. Now in the left box you will be able to see a form icon with a + on it. Double click this to expand it and then choose loaded forms. You should be able to see your form in the list. Choose it. Now in the middle list you should be able to find your combo box. Double click on this and now yopu will see some code appear in the TOP window. Press the OK button to copy the code the the field in the query. Now in the Sort field choose Ascending.
The problem is that I wont to be able to let my users choose which field the query should be sortet by. The choise is made in a COMBO-box on a form and it is the value of that combo i would like to put into my ORDER BY statement
I know i'm doing something wrong - that's why i-m asking the professionals :-)
Rene.. is the field which the ORDER BY is using on a sub form? If you use the wizard then you willhave to double click on th emain form in the left list to expand it so that you can see the sub forms.
Som jeg sagde tidligere, kan du ikke have variabler i SQL kodens ORDER BY sætning. Som du selv er inde på kan du lave en query for hver sorteringsfelt.
No it's not on a subform. I simply need du take the value of the COMBO i.e. "Ydelse" and put it i my query sql-statement:
ORDER BY <tablename>.COMBO.value (where the combo values are exatly like the names of the fields in the table that i whant it to be possible to sort by).
Does this brighten the problem? Or do you want the database to take a closer look?
OKI - det virker bare underligt at når jeg selv knaster et felt navn ind i sql'en så kører det - nå men der er vel ikke andet at gøre end at begynde at IF'e sig frem når der skal søges :-)
Hej jkrons - jep men den må så ligge i ORDER BY funktionaliteten . Tak for hjælpen. Jeg er normalt LotusNotes mand - men har lige dette her projekt der skal afvilkes i access......
I had to accept the fact that the ORDER BY statement not chould be set by value of a COMBO - so it ended up with that I made one query for each af my sorting possibillities. It's not elegant but it works
Thanks for you effort .
René
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.