database very slow when searching. Is there a way to speed it up
I have a database which tracks samples for storage one can delte and ad samples. When adding samples the database searches the first open spot to place a sample. But when I add samples it takes a lomg time before the search is completed.
This is how I programed the search.
Private Sub Form_AfterUpdate()
Dim rsSamples As DAO.Recordset
Dim rsLocaties As DAO.Recordset
Dim intTeller As Integer
Dim intGeplaatst As Integer
Dim strVoorwaarde As String
If Not Me.NewRecord Then Exit Sub
Set rsLocaties = CurrentDb.OpenRecordset("tblVatposities", dbOpenDynaset)
Set rsSamples = CurrentDb.OpenRecordset("samples per locatie", dbOpenDynaset)
If Not IsNumeric(Me.aantal_samples) Or Not Me.aantal_samples > 0 Then
MsgBox "Ongeldige waarde ingebracht voor aantal samples"
Me.aantal_samples.SetFocus
Cancel = True
Exit Sub
End If
For intTeller = 1 To Me.aantal_samples
Do Until rsLocaties.EOF
strVoorwaarde = "Locatie = " & rsLocaties![VatPositieId]
rsSamples.FindFirst strVoorwaarde
If rsSamples.NoMatch Then
rsSamples.AddNew
rsSamples![Patientennummer] = Me.donornr
rsSamples![Materiaal] = Me.matriaal
rsSamples![Locatie] = rsLocaties![VatPositieId]
rsSamples![datum afname] = Me.datum_afname
rsSamples![datum invoer] = Me.datum_invoer
rsSamples.Update
intGeplaatst = intGeplaatst + 1
Exit Do
End If
rsLocaties.MoveNext
Loop
rsLocaties.MoveFirst
Next intTeller
MsgBox "Er werden " & Me.aantal_samples & " samples geplaatst"
End Sub
tblvatposities contains 20000 positions.
Has anyone a way to speed things up
I have a database which tracks samples for storage one can delte and ad samples. When adding samples the database searches the first open spot to place a sample. But when I add samples it takes a lomg time before the search is completed.
This is how I programed the search.
Private Sub Form_AfterUpdate()
Dim rsSamples As DAO.Recordset
Dim rsLocaties As DAO.Recordset
Dim intTeller As Integer
Dim intGeplaatst As Integer
Dim strVoorwaarde As String
If Not Me.NewRecord Then Exit Sub
Set rsLocaties = CurrentDb.OpenRecordset("tblVatposities", dbOpenDynaset)
Set rsSamples = CurrentDb.OpenRecordset("samples per locatie", dbOpenDynaset)
If Not IsNumeric(Me.aantal_samples) Or Not Me.aantal_samples > 0 Then
MsgBox "Ongeldige waarde ingebracht voor aantal samples"
Me.aantal_samples.SetFocus
Cancel = True
Exit Sub
End If
For intTeller = 1 To Me.aantal_samples
Do Until rsLocaties.EOF
strVoorwaarde = "Locatie = " & rsLocaties![VatPositieId]
rsSamples.FindFirst strVoorwaarde
If rsSamples.NoMatch Then
rsSamples.AddNew
rsSamples![Patientennummer] = Me.donornr
rsSamples![Materiaal] = Me.matriaal
rsSamples![Locatie] = rsLocaties![VatPositieId]
rsSamples![datum afname] = Me.datum_afname
rsSamples![datum invoer] = Me.datum_invoer
rsSamples.Update
intGeplaatst = intGeplaatst + 1
Exit Do
End If
rsLocaties.MoveNext
Loop
rsLocaties.MoveFirst
Next intTeller
MsgBox "Er werden " & Me.aantal_samples & " samples geplaatst"
End Sub
tblvatposities contains 20000 positions.
Has anyone a way to speed things up