Avatar billede janbach Nybegynder
27. maj 2006 - 10:39 Der er 14 kommentarer og
1 løsning

Antal resultater

Hej Eksperter
Jeg har en form, som henter sine resultater fra en Query. Der er i formen en bladrefunktion og jeg vil gerne kunne vise noget i stil med "Resultat 1 ud af 40". Hvordan kan jeg lave dette?
Avatar billede terry Ekspert
27. maj 2006 - 11:00 #1
Just an idea, which may or may not work in all situaitions.

Private Sub Form_Current()
Me.Caption = "Resultat " & Me.Recordset.AbsolutePosition + 1 & " ud af " & Me.Recordset.RecordCount


End Sub
Avatar billede janbach Nybegynder
27. maj 2006 - 11:08 #2
How do i append it to the textbox?
Avatar billede terry Ekspert
27. maj 2006 - 11:11 #3
Not sure what your trying to do exactly. If you want to display it in an unbound text box then something like this should work.

me.YourTextBox = "Resultat " & Me.Recordset.AbsolutePosition + 1 & " ud af " & Me.Recordset.RecordCount
Avatar billede terry Ekspert
27. maj 2006 - 11:14 #4
I was a little unure if it worked also if you filtered the records, but I've just tested and it seems to be OK there too.
Avatar billede janbach Nybegynder
27. maj 2006 - 11:17 #5
I have a form where i want to show the results of a query. But it would be nice if the user knew how many results there were. On the form there are two buttons - a next and a previous button. Between these i would like it to show where the user is.
Avatar billede janbach Nybegynder
27. maj 2006 - 11:19 #6
If i right click the textbox, the only way i seem to be able to write in the code, is if i choose "Build Event". If i do this the code will look like this:
Option Compare Database

Private Sub Text15_BeforeUpdate(Cancel As Integer)
Me.Text15 = "Resultat " & Me.Recordset.AbsolutePosition + 1 & " ud af " & Me.Recordset.RecordCount

End Sub

And this does not seem to work.
Avatar billede terry Ekspert
27. maj 2006 - 11:20 #7
Normally you can see that if you use Access's built in navigation buttons. If you dont use that then you can use some code similar to what I have given and place it in the On Current event. Have you tried the example I gave?
Avatar billede terry Ekspert
27. maj 2006 - 11:21 #8
the code has to be on the forms On Current Event
Avatar billede janbach Nybegynder
27. maj 2006 - 11:46 #9
It is on the Form current Event now - but the text box is not filled. The code is like this:

Private Sub Text15_CurrentEvent(Cancel As Integer)
Me.Text15 = "Resultat " & Me.Recordset.AbsolutePosition + 1 & " ud af " & Me.Recordset.RecordCount

End Sub
Avatar billede janbach Nybegynder
27. maj 2006 - 11:47 #10
I have removed the built in navigation button - they are very practical, but ugly as h...:)
Avatar billede janbach Nybegynder
27. maj 2006 - 11:51 #11
Sorry - i see the mistake i made now. It works now! Thank you very much.

By the way. Can you tell me how to fix my next and previous button, so that they dont "go to far"? Right now i get an error when there is no more results from the query.
Avatar billede terry Ekspert
27. maj 2006 - 12:00 #12
I would think its enough to just catch the error using


On Error goTo SomePointOrOther

SomePointOrOther:
..Error handler goes here

Maybe just a resume Next


Janbach I'm off out of the door now, back tomorrow, hope you get it working
Avatar billede janbach Nybegynder
27. maj 2006 - 12:06 #13
Thank you very much - I will try that. I just noticed that when i enter the form it says Resultat 1 ud af 1 even though the is 3. When i hit the next button is changes to the right number.

Any ideas why?
Avatar billede terry Ekspert
28. maj 2006 - 15:03 #14
No idea as to why it shows Resultat 1 ud af 1. I have an example here and it works as expected.
I'll take a look at your dB if you like, maybe I can see the problem?
Avatar billede terry Ekspert
06. juni 2006 - 21:09 #15
Thanks Jan, hope you can it working as you want.
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