Hi
I wrote this function:
[CODE=vb]Function UpdateLongfunct ieFEVFVC()
Set db = CurrentDb
Dim percfev As Double
Dim percfvc As Double
Set rst = db.OpenRecordse t("SELECT eadnr, datum, fev1, fvc, lengte FROM Longfunctie;")
Do Until rst.EOF
percfvc = 0
percfev = 0
If (rst.Fields(4). Value <> Null Or rst.Fields(4).V alue <> 0 Or Nz(rst.Fields(4 ).Value)) Then
Set rst2 = db.OpenRecordse t("SELECT DISTINCT sex FROM patient WHERE eadnr = " & rst.Fields(0).V alue & ";")
If (rst.Fields(2). Value <> Null Or rst.Fields(2).V alue <> 0 Or Nz(rst.Fields(2 ).Value)) Then
If (rst2.Fields(0) .Value = "m") Then
percfev = rst.Fields(2).V alue * 1000 / Exp(-2.86521 * Log(10) + 2.87294 * Log(rst.Fields( 4)))
Else
percfev = rst.Fields(2).V alue * 1000 / Exp(-2.60565 * Log(10) + 2.74136 * Log(rst.Fields( 4)))
End If
'Debug.Print percfev & " " & rst2.Fields(0). Value
End If
If (rst.Fields(3). Value <> Null Or rst.Fields(3).V alue <> 0 Or Nz(rst.Fields(3 ).Value)) Then
If (rst2.Fields(0) .Value = "m") Then
percfvc = rst.Fields(3).V alue * 1000 / Exp(-2.9236 * Log(10) + 2.936 * Log(rst.Fields( 4)))
Else
percfvc = rst.Fields(3).V alue * 1000 / Exp(-2.704 * Log(10) + 2.8181 * Log(rst.Fields( 4)))
End If
End If
db.Execute ("UPDATE Longfunctie SET [%fev1] ='" & percfev * 100 & "', [%FVC] ='" & percfvc * 100 & "' WHERE eadnr = " & rst.Fields(0).V alue & " AND Datum = #" & rst.Fields(1).V alue & "#;")
End If
rst.MoveNext
Loop
Debug.Print rst.RecordCount
rst.Close
rst2.Close
Set rst = Nothing
Set rst2 = Nothing
Set db = Nothing
End Function[/CODE]
It works for most of the records in the table but for some reason it skips some records. I have no idea what causes this... The table I load into rst has 8975 records and the print of the recordcount gives the correct number of records.
Can someone check this?? I realy don't see any errors in the function...
Greetz
Twanne
Please is just a word, thanx is a gift
I wrote this function:
[CODE=vb]Function UpdateLongfunct ieFEVFVC()
Set db = CurrentDb
Dim percfev As Double
Dim percfvc As Double
Set rst = db.OpenRecordse t("SELECT eadnr, datum, fev1, fvc, lengte FROM Longfunctie;")
Do Until rst.EOF
percfvc = 0
percfev = 0
If (rst.Fields(4). Value <> Null Or rst.Fields(4).V alue <> 0 Or Nz(rst.Fields(4 ).Value)) Then
Set rst2 = db.OpenRecordse t("SELECT DISTINCT sex FROM patient WHERE eadnr = " & rst.Fields(0).V alue & ";")
If (rst.Fields(2). Value <> Null Or rst.Fields(2).V alue <> 0 Or Nz(rst.Fields(2 ).Value)) Then
If (rst2.Fields(0) .Value = "m") Then
percfev = rst.Fields(2).V alue * 1000 / Exp(-2.86521 * Log(10) + 2.87294 * Log(rst.Fields( 4)))
Else
percfev = rst.Fields(2).V alue * 1000 / Exp(-2.60565 * Log(10) + 2.74136 * Log(rst.Fields( 4)))
End If
'Debug.Print percfev & " " & rst2.Fields(0). Value
End If
If (rst.Fields(3). Value <> Null Or rst.Fields(3).V alue <> 0 Or Nz(rst.Fields(3 ).Value)) Then
If (rst2.Fields(0) .Value = "m") Then
percfvc = rst.Fields(3).V alue * 1000 / Exp(-2.9236 * Log(10) + 2.936 * Log(rst.Fields( 4)))
Else
percfvc = rst.Fields(3).V alue * 1000 / Exp(-2.704 * Log(10) + 2.8181 * Log(rst.Fields( 4)))
End If
End If
db.Execute ("UPDATE Longfunctie SET [%fev1] ='" & percfev * 100 & "', [%FVC] ='" & percfvc * 100 & "' WHERE eadnr = " & rst.Fields(0).V alue & " AND Datum = #" & rst.Fields(1).V alue & "#;")
End If
rst.MoveNext
Loop
Debug.Print rst.RecordCount
rst.Close
rst2.Close
Set rst = Nothing
Set rst2 = Nothing
Set db = Nothing
End Function[/CODE]
It works for most of the records in the table but for some reason it skips some records. I have no idea what causes this... The table I load into rst has 8975 records and the print of the recordcount gives the correct number of records.
Can someone check this?? I realy don't see any errors in the function...
Greetz
Twanne
Please is just a word, thanx is a gift
Comment