VBA访问IF条件

时间:2014-08-04 11:31:46

标签: vba ms-access

我有一个问题,我的IF在某种程度上没有验证索引0上字段的良好价值。

这是UDPATED代码:

Private Sub Parametri()

Dim db As dao.Database
Dim rs As dao.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("ribe")


rs.MoveLast
rs.MoveFirst

For i = 0 To rs.RecordCount
    If rs.Fields(i).Value > 2 Then

        Debug.Print rs.Fields("Lokacija_GS")
        rs.MoveNext
    End If
Next



End Sub

结果如下:

1
43.626145
43.626145
43.630122
43.632358
43.625833

" 1"应该跳过索引0 ...但它不是吗?

这是表格:

enter image description here

因此,例如,如果某行为0或1或NULL,我想跳过它......

1 个答案:

答案 0 :(得分:2)

这是正确的代码,

Private Sub Parametri()
    Dim db As dao.Database
    Dim rs As dao.Recordset

    Set db = CurrentDb
    Set rs = db.OpenRecordset("ribe")

    rs.MoveLast
    rs.MoveFirst

    Do While Not rs.EOF
        If rs.Fields("Lokacija_GS").Value > 2 Then _
            Debug.Print rs.Fields("Lokacija_GS")
        rs.MoveNext
    Loop

    Set rs = Nothing
    Set db = Nothing
End Sub