Avatar billede Jørgen Kirkegaard Professor
26. januar 2016 - 20:40 Der 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.

How to?
Avatar billede terry Ekspert
27. januar 2016 - 11:35 #1
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.
Avatar billede Jørgen Kirkegaard Professor
27. januar 2016 - 14:49 #2
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..
Avatar billede terry Ekspert
27. januar 2016 - 15:09 #3
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.

Any better?
Avatar billede Jørgen Kirkegaard Professor
27. januar 2016 - 15:24 #4
Hmm - nårh - næh. Jeg ved ikke lige, hvad du mener med tekstfelt over combotext area.. i en subform...

Mit datagrundlag (Og jeg skal da liii sige, at det er en tænkt eksempel :-):

Postnr Vejnavn
--------------
2300  Spaniensgade
2300  Holmbladsgade
3140  Blekingevej


-----
(Mainform: Firmaer)
-----


Subform:

Afdelinger PostNr Vejnavn
-------------------------
KbhA      2300      (Drop down med Spaniensgade og Holmbladsgade)
Sjælland  3140  (Drop down med Blekingevej - som er den eneste)
Avatar billede terry Ekspert
27. januar 2016 - 15:56 #5
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.
Avatar billede terry Ekspert
27. januar 2016 - 15:56 #6
Bit of a mouth full.

If I get a bit of time I'll put a simple example togther
Avatar billede Jørgen Kirkegaard Professor
27. januar 2016 - 16:28 #7
"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?
Avatar billede Jørgen Kirkegaard Professor
27. januar 2016 - 16:34 #8
Korrektion: Selvfølgelig er jeg så langt så jeg kan skille dataene ud - se bort fra første afsnit..
Avatar billede terry Ekspert
27. januar 2016 - 16:41 #9
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.
Avatar billede Jørgen Kirkegaard Professor
27. januar 2016 - 16:52 #10
"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.
Avatar billede terry Ekspert
27. januar 2016 - 17:14 #11
If you have a test dB then maybe you could send it and I'll try and find a bit of time tomorrow to look at it.

ekspertenATsanthlell.dk
AT = @
Avatar billede terry Ekspert
27. januar 2016 - 17:16 #12
Avatar billede Jørgen Kirkegaard Professor
27. januar 2016 - 17:51 #13
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 :-)
Avatar billede Jørgen Kirkegaard Professor
27. januar 2016 - 18:13 #14
Jeg får mail til eksperten(at)santhlell.dk retur...
Avatar billede terry Ekspert
27. januar 2016 - 18:27 #15
santhell.dk

But if you cant use the idea in link you will need to use a single form.
Avatar billede Jørgen Kirkegaard Professor
25. februar 2016 - 11:15 #16
Selvom den ikke blev løst, er det jo også et svar. Jeg vil evt. mose videre med det. Venligst begge læg et svar, så deler I points.
Avatar billede terry Ekspert
25. februar 2016 - 11:25 #17
:-)
Avatar billede terry Ekspert
16. maj 2016 - 17:22 #18
tak
Avatar billede Ny bruger Nybegynder

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.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester