Avatar billede hermanlaksko Nybegynder
14. december 2006 - 17:46 Der er 19 kommentarer og
1 løsning

Combobox - hvor er jeg ?

Når man foretager et valg i en comgobox glemmer comboboxen tilsyneladdende hvor man er, næste gang man åbner comboboxen starter man igen på "førstepladsen", det kan være lidt irr.... især hvis man har flere hundrede records i den valgte box.

Fx har jeg en form vist som "datasheet"/regneark i denne form har jeg en combobox der indeholder datoer, det kan fx. være indeværende måned eller år, det er derfor upraktisk at skulle starte med 1-1-2006 hver gang, især hvis man nu er ved at taste data ind i juni og er nået til den 12.

Man kan,naturligvis skrive en del at datoen ind, hvorefter den kommer frem men det ville være lettere hvis også comboboxen var "spolet" frem til 11-06-2006 (som kunne være det sidst foretagne valg)
På forhånd tak.
Avatar billede terry Ekspert
14. december 2006 - 19:18 #1
So you need som eway to remember what you previously selected. One way to do this is have the combo box BOUND to a field in a tabel. So when you choose another value form the combo you alter the underlaying table. Next time you start up it will show the previosuly selected value.

The table could just have one record so it will be necessary to alter some parameters so that it only cycles on the one record.

Or you could save the value in a table on the combo's AFTER UPDATE event. And use Dlookup function to retrieve it again.
Avatar billede -anders- Juniormester
14. december 2006 - 20:05 #2
Du kan også anvende registry til dette, prøv evt. at følge nedenstående eks.

'Eks. tager udgangspunkt i at din combo kun indeholder en kolonne'

'På din combo efter opdatering lægger du denne kode:'

Private Sub cbovalue_AfterUpdate()
SaveSetting "db1.mdb", "Formular1", "test", Me!cbovalue
End Sub

'På formens ved indlæsning lægger du denne kode'

Private Sub Form_Load()
Me!cbovalue = GetSetting("db1.mdb", "Formular1", "test")
End Sub

'Lidt forklaring'
'I savesetting angiver du navnet på db husk altid .mdb efter, derefter angiver du navnet på den aktuelle formular, så skriver du selve nøglen der skal gemmes i regestry, i dette eks. hedder nøglen "test", og til sidst skrives værdien af det valgte i comboen i nøglen "test"'

'GetSetting henter så den gemte værdi i nøglen "test" og indsætter den i comboen når form loades/åbnes'

'Det er faktisk meget anvendeligt, men det gælder om at holde tungen lige i munden :o).

Du skal naturligvis ændre diverse objektnavne til dine egne.
Avatar billede -anders- Juniormester
14. december 2006 - 20:07 #3
Hvis i Access hjælpfilen søger på getSetting, SaveSetting, er der lidt mere hjælp at hente
Avatar billede -anders- Juniormester
14. december 2006 - 20:11 #4
Det skal lige nævnes at ovenstående metode ikke er fejlsikret, hvis din combo er Null, altså indeholder ingen ting vil det fejle
Avatar billede hermanlaksko Nybegynder
15. december 2006 - 07:30 #5
Hi Terry Thx yr reply, however the problem is not how to remember but how to make it work. How to store the needed data is solved.

Hej Anders Tak for dit meget intressante svar, som jeg har eksperimenteret lidt med for at lette dets brug er jeg kommet frem til dette:
SaveSetting CurrentDb.Name, Me.Name, "AValue", Me!MyCbo.Value

Men denne løsning giver min combo den gemte værdi og flytte ikke selve comboboxen ned til den ønskede linie.

Tak for din advarsel mht. Null værdien, mit svar blev dog ikke en Null værdi men "" det løses dog nemt med denne lille funktion:
Function IsBlank(V As Variant) As Boolean
On Error Resume Next
V = "" & V
If Len(V) = 0 Then IsBlank = True
End Function

Denne søger på isempty, isnull, etc. ret god til at teste for alle tomme værdier.

Har du en ide til hvordan jeg får selve somboboxen til at flytte sig istedet for at få værdien?
Det må være et eller andet med OnDropDown..... ;-)
På forhånd tak
Avatar billede -anders- Juniormester
15. december 2006 - 07:58 #6
Hejsa

Du skriver i dit spørgsmål(som kunne være det sidst foretagne valg), jeg har desværre ikke lige et bud på den sidste delt af det, men jeg er sikker på der nok skal komme nogen forbi med et eller flere forslag :o)
Avatar billede terry Ekspert
15. december 2006 - 17:55 #7
Maybe I've missed something. Are yoy saying that you have a continuous form where there is a field (combo) from where you selected a date. And you want to be able to jump to the next available date in the list?

If I've understood you correctly then ther is no need to save anything in th eregistry, or another table, you alreday have the necessary information in the table which the form is based on.

This is just an example. 

Private Sub Dato_GotFocus()
   
    Me.Dato.Dropdown 'THis drops down the Combo named dato
    If Me.Recordset.RecordCount = 0 Then 'is this teh very first record I enter?
        Me.Dato = DFirst("dato", "tblDato") 'Take the first date from the table which th ecombo takes its dates from.
    Else
        Me.Dato = CDate(DMax("dato", "tblDates")) + 1 'Find the current max date and add one
    End If
   
End Sub
Avatar billede hermanlaksko Nybegynder
16. december 2006 - 07:33 #8
Hi Terry
I have tryed your suggestion, however whenever giving the field a value the combo will not move, it will accept the given value as a value for the field and close (the dropdown) and a newrecord is added.
What I am looking for is to make the combo move to a surtan value in the combo-list and then wait for the user to choose any value from the open combo.
Avatar billede terry Ekspert
16. december 2006 - 14:03 #9
Firsdt, you dont need to continue rejecting our answers. Wait until the question is closed and then decide what to reject or not.

I have mad an example which shows that the answer I gave 15/12-2006 17:55:46 does work. So it should be able to get it to work in your dB too. At least I hope so.

http://home1.stofanet.dk/santhel/Download/750814.zip
Avatar billede terry Ekspert
16. december 2006 - 14:11 #10
This is JUST an example to show that you can open the combo and select a value. In Access selecting a value automatically put the selected value in the text part of the combo, it isnt possible to move to a value WITHOUT it being put in the text part.
It will very likley also be necessary to disbale the code if you place the focus on the combo in an already existing record. But as I said this is just an example.
Avatar billede hermanlaksko Nybegynder
18. december 2006 - 10:14 #11
Hi Terry
Ok I was not sure on how to handle answers - ok noted - thx

Ok thatnk I will checkout your example, but you know I really just want the combo box scroll bar to move.
Avatar billede terry Ekspert
18. december 2006 - 12:37 #12
Hi Herman
As I mentioned, it isnt possible, as far as I know, to just get it to scroll while it is opne, without actually putting the selected row in the text box.
But I might have an idea which you can use.

Make the combo undbound, so that while you move through the list it doesnt start updaining your record.
Now place a bound text box over the combo. Name the text box txtDato.

Now you need to add this to the AFTER update event of the combo

Me.txtDato = me.Dato 'Dato is the combo
Avatar billede terry Ekspert
18. december 2006 - 12:38 #13
Put th etext box over the text area of the combo so that the drop down button is still visible.
Avatar billede hermanlaksko Nybegynder
18. december 2006 - 16:41 #14
Ok Terry
It was not the solution I was hoping for, however I will give you the points for your persistancy in trying to find another way.
If I, or any one else, find the solution, I will post it here.
Thx again.
Avatar billede terry Ekspert
18. december 2006 - 17:58 #15
Thanks

Does the idea do what you want?
I dont think it is possible to do it any other way
Avatar billede hermanlaksko Nybegynder
19. december 2006 - 14:22 #16
No it was not what I was hoping for.
I belive that what I want is poss via an ocx, however I have no idear witch one.. ;-)

The solution ended was then to give the end user a week-selection option in order to limit the amount of data in the drop-down list.
I am still looking for the ocx-way and will post it if/when found.
Avatar billede terry Ekspert
19. december 2006 - 15:29 #17
This wasnt mentioned in the original question, if you can give a bit more information as to what your trying to do then maybe we can help
Avatar billede hermanlaksko Nybegynder
19. december 2006 - 15:48 #18
Ok I understand what you are trying to say, but I do not agree.
My question was and is how to move the combo, or the scroll bar in the combo, if you like.
Also as I ask a question, I do not stop investigating myself, I try to find a solution and the further one works into a problem the more one discovers.

Also as the discusstion here goes on, one gets new idears, as one would get in any other discussion.
I am thankfull for your effords and I am truely sorry if I have offended you in any way!

However I have found one solution that does the trick, allthough not the way I want it (ocx):
The trick is to set the DefaultValue on the "OnEnter" event before the .DropDown, and not the value of the combo, then on the "OnExit" event, set the DefaultValue="" to "clean" the combo again.
Avatar billede terry Ekspert
19. december 2006 - 17:08 #19
You havent offended me at all, and I've only been trying to find
the solution which best suites your requirement.

Anyway, if you have a working solution then lets leave it at that.
Have a good Xmas/New Year
Avatar billede hermanlaksko Nybegynder
18. december 2007 - 09:58 #20
Set Re = CurrentDb.OpenRecordset(Left(SqlStr, InStr(1, SqlStr, "Order By") - 1) & " Order By ArbID")
    If Re.RecordCount > 0 Then
        Re.MoveLast
        Svar = Re!DagID
    Else
        Svar = 1
    End If
    Me!DagID.DefaultValue = Svar + 1
    Me!DagID.Dropdown
Løsingen var at ændre DefaultValue og så lægge 1 til for at få næste mulige værdi.
Selv on jeg selv fandt løsningen - vil jeg alligevel gerne sige tak for hjælpen og indsatsen med dette problem.
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
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

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



Seneste spørgsmål Seneste aktivitet
I dag 06:10 Excel åbner fil i kæmpe format Af Aske i Excel
I går 22:00 Datafordeler Af Lsk i PHP
I går 12:37 Summere beløb pr. dato Af TTA i Excel
31/1022:44 Tilslutte chassic fans Af viking69 i PC
31/1020:28 LED lysstofrør Af ErikHg i Fri debat