26. januar 2016 - 20:40Der er
17 kommentarer og 1 løsning
Drop-down afhængig af data i samme linje.
Hej.
I min Access 365 database har jeg f.eks. vejnavne og postnumre, hvor vejene ligger.
I rækkerne i en subform har jeg et felt, f.eks. postnummer. Når jeg har valg dette dette, f.eks. 2300, skal jeg i det næste felt kunne vælge blandt vejnavne, men kun i dét postnummer, jeg lige har valg.
Det dynamiske felt Vejnavn skal jo have ændret mulighederne, afhængig af postnummer, men det kan jeg kun få den til - i efterfølgende rækker - ved at lave en refresh, som så sletter vejnavnene i rækken over.
I seem to recall that a solution to his is to place a text box over the combo text area so that it displayed the value which was chosen when creating/editing the record.
Jeg er ikke helt sikker på hvad du mener, for rækken er jo ikke dannet endnu. Jeg indtaster postnr. i det ene felt, men det er jo ikk lagret i dabasen på dette tidspunkt. Herefter - i samme linje - skal min komboboks/liste justeres efter dette. Jeg har prøvet med et query, men værdien [formular].[subform]![postnr] findes ikke..
I assume you have a dropdown for postnr. and another for vejnavn.
The contents of postnr dropdown will be the same for ALL rows, but the vejnavn dropdown you want to change for the specific postnr, but this isn't possible. If you change contents of a combo then it applies to ALL rows not just the current.
So a way around this is to have a text field over the combo text area and this is used to show the chosen vejnavn, also when the contents of the vejnavn combo get changed because you choose a different postnr.
Afdelinger PostNr Vejnavn ------------------------- KbhA 2300 (Drop down med Spaniensgade og Holmbladsgade) Sjælland 3140 (Drop down med Blekingevej - som er den eneste)
OK, lets say you choose 2300 and then Holmbladsgade. Then you go to the next record and choose 3140.
You want the vejnavn combo to only contain Blekingevej, yes?
But when you do this the combo for the first row (2300) also changes, yes?
So we need a way of showing the correct Vejnavn on already existing records while you add new records with possible different Postnr.
I assume that you have a table with Postnr Vejnavn and you will also need a table for the sub form data containing Afdelinger PostNr Vejnavn
I guess that you are currently using combo for PostNr and Vejnavn, and this is where you have the problem.
In the recordsource for the subform you need to include the field Vejnavn, because this is where the correct data is saved, not in the combo which you only use to choose the Vejnavn.
Now because the data in the Vejnavn combo will change for ALL rows when you choose another postnr. you need to have the field from the table which sub form is bound to, on the sub form also.
And if you put it over the text area of the combo you see which Vejnavn you chose. Then if you go to another record and choose another postnr. this will NOT change the Vejnavn field for existing records. But if you drop down the combo for existing records you will see Vejnavn for the last created/changed row.
"OK, lets say you choose 2300 and then Holmbladsgade. "Wauw - I now realize that I am not even this far (though I have been)!! My combo "Select .. where postnr=form!MySubForm" suddenly doesn't work!! I need to look at this. But still:
Din allersidste bemærkning lyder ikke så godt, hvis jeg forstår dig ret: "But if you drop down the combo for existing records you will see Vejnavn for the last created/changed row." Altså, hvis f.eks. står i min tredje linje og har indtastet det hele (med postnr=3140) og så går til første linje, så vil comboboks vise vejnavne for 3140?
Og jeg er ikke helt sikker på, hvad du mener med:
".. put it over the text area of the combo" Is "over" op over, dvs. i hovedform?
Din allersidste bemærkning lyder ikke så godt, hvis jeg forstår dig ret: "But if you drop down the combo for existing records you will see Vejnavn for the last created/changed row." Altså, hvis f.eks. står i min tredje linje og har indtastet det hele (med postnr=3140) og så går til første linje, så vil comboboks vise vejnavne for 3140?
Yes, the combo will show 3140, but the text field which is covering the combo will show the correct vejnavn.
Oh, and you need some code in the on current event which requeries the vejnavn combo when you move between records. This is so the combo again shows correct vejnavn for the current postnr.
Just something to think about.
A combo has a selection area which will show your vejnavn, and it also has the text area showing the selected vejnavn. Its this area we want to use to continue to show the SELECTED vejnavn, even though the selection area shows other vejnavn.
"Just something to think about"-- I will. Men det irriterer mig, at jeg ikke kan bruge "where ... = form!Myform!Postnr" til at referere til det indtastede PostNr, når jeg skal lave en comboselect.
Thanks a lot - Yap, dette er præcis problemet. Det virker som en høker-løsning, så jeg vil holde mig fra det! Ellers tak for hjælpen. Sender lige en mail. Så kan du sende et svar :-)
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.