Hello my good people!
It have come to my mind that stored procedures can help us speed up the retrival of records from our SQL server.
I have now made a stored procedure at our server which is called "StoreProcedure 1"
normally i would use this code to populate listboxes with information. I would prefer to use a stored procedure cause of the speed advantage i think it has.
Can anyone help me on how to open a stored procedure and running trough all the records and retriving the data. The collection and all that you need not to think of, just how to open the procedure and retrive all the rows from it
It have come to my mind that stored procedures can help us speed up the retrival of records from our SQL server.
I have now made a stored procedure at our server which is called "StoreProcedure 1"
normally i would use this code to populate listboxes with information. I would prefer to use a stored procedure cause of the speed advantage i think it has.
Code:
Sub Populer_Liste_avansert(SQL As String, Skjema As String, Liste As String)
Dim r As DAO.Recordset
Dim Coll As New Collection
Dim Tmpstr As String
Dim Fieldstr As Long
'--------------------------
'Åpne recordset
'--------------------------
Set r = CurrentDb.OpenRecordset(SQL, dbOpenSnapshot, dbSeeChanges)
'--------------------------
'Finn overskrifter
'--------------------------
For x = 1 To r.Fields.Count
Coll.ADD (r.Fields(x - 1).Name)
Next x
'--------------------------
'Lag en string med overskriftene
'--------------------------
For x = 1 To Coll.Count
If Not Tmpstr = "" Then
Tmpstr = Tmpstr & ";" & Coll(x)
Else
Tmpstr = Coll(x)
End If
Next x
'--------------------------
'Endre kildetype på listen
'--------------------------
Forms(Skjema).Controls(Liste).RowSourceType = "Verdiliste"
'--------------------------
'Sett inn overskriftene i listen
'--------------------------
Forms(Skjema).Controls(Liste).RowSource = ""
Forms(Skjema).Controls(Liste).AddItem Tmpstr
'--------------------------
'Hent og sett inn verdiene
'--------------------------
'--------------------------
'Gå gjennom alle postene
'--------------------------
Do Until r.EOF
I = I + 1
'--------------------------
'Tøm Coll
'--------------------------
For x = 1 To Coll.Count
Coll.Remove (1)
Next x
'--------------------------
'Hent verdier
'--------------------------
For x = 1 To r.Fields.Count
Coll.ADD (r.Fields(x - 1).Value)
Next x
'--------------------------
'Lag string
'--------------------------
Tmpstr = ""
For x = 1 To Coll.Count
If Not Tmpstr = "" Then
Tmpstr = Tmpstr & ";" & Coll(x)
Else
Tmpstr = Coll(x)
End If
Next x
'------------------------------------
'Sjekk om max listeinnhold er oppnådd
'------------------------------------
Fieldstr = Fieldstr + Len(Tmpstr)
If Fieldstr > 32736 Then
imax = 200
GoTo slutt
End If
'--------------------------
'Sett inn post i listen
'--------------------------
Forms(Skjema).Controls(Liste).AddItem Tmpstr
r.MoveNext
Loop
slutt:
r.Close
Set rs = Nothing
Set Coll = Nothing
End Sub
Can anyone help me on how to open a stored procedure and running trough all the records and retriving the data. The collection and all that you need not to think of, just how to open the procedure and retrive all the rows from it

Comment