Avatar billede birkebjerg Nybegynder
16. juli 2005 - 10:13 Der er 6 kommentarer og
1 løsning

Listbox default værdier

Hejsa

Jeg har en listbox der henter dens værdier i en tabel. Er det muligt at lave så udfra data i en anden tabel at nogle af felterne er default valgt.
Avatar billede terry Ekspert
16. juli 2005 - 15:43 #1
I would think it very possible to do waht you want to do.

If the other table contains the records you want to have selected then you could make a recordset from the other table and then loop through each record in the record set then loop through entries in the listbox and if you find a macth then select it.
Avatar billede birkebjerg Nybegynder
16. juli 2005 - 17:37 #2
It sounds like a way to do it. What is the syntax to select it, when there is a match?
Avatar billede terry Ekspert
17. juli 2005 - 10:15 #3
here is another idea.
Make a query where you have both tables. Select the fields from the first table which you want to see in the listbox. JOIN the two tables on th efields which related them. Change the join to an OUTER join so you always see all records from the first table, even if there is not a related record in the other table.

Now use the query as the Row Source to the listbox.

Now use some code like this. This example has four column. The first three columns come from the first table and the last column comes from the other table. Columns in the listbox are numbered 0 to column count -1. So the last column is 3. This column will be empty if there is NOT a related record. And if there is not then we do not want to mark the row as selected.

NOTE: The listbox must be set to Mulit select otherwise you can only select one row.


Private Sub Form_Open(Cancel As Integer)
Dim i As Integer

    For i = 0 To Me.List0.ListCount - 1
   
        If Len(Me.List0.Column(3, i)) > 0 Then Me.List0.Selected(i) = True
   
    Next i

End Sub
Avatar billede terry Ekspert
17. juli 2005 - 10:16 #4
I forgot to say that you also need to select the related field in the other table when you make your query.
Avatar billede terry Ekspert
18. juli 2005 - 21:52 #5
status?
Avatar billede birkebjerg Nybegynder
20. juli 2005 - 16:10 #6
Sorry for the waiting, I started working again, which meens less time having fun. Thanks for your time, maybe I look into it later, but for now I don't have time.
Avatar billede terry Ekspert
20. juli 2005 - 19:23 #7
OK and thanks, drop a comment if you still need help. I'm off on holiday next week :o)
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