ms-accessvbawith-statementms-access-2003

With statement for recordset field specification in Access 2003 VBA


I know of two ways to specify a field in a record set with VBA:

FooTable!BarField = 1
FooTable("Bar Field") = 2

But what happens in a With block?

With FooTable
    !BarField = 1
    ("Bar Field") = 2
End With

Is it possible to do both, or is there a workaround?


Solution

  • The following are all equivalent:

    With FooTable
        .Fields("Bar Field").Value = 2  '.Value is default property of a Field object'
        .Fields("Bar Field") = 2  
        ![Bar Field] = 2
    End With