MS Access ADODB method

  1. Dim cn As New ADODB.Connection
  2. Dim rs As ADODB.Recordset
  3. Dim strSQL As String
  4.  
  5. strSQL = "Select * from Employees ORDER BY [LastName],[FirstName];"
  6.  
  7. Set rs = New ADODB.Recordset
  8.  
  9. With rs
  10.   .Source = strSQL
  11.   .ActiveConnection = CurrentProject.Connection
  12.   .CursorType = adOpenDynamic
  13.   .LockType = adLockOptimistic
  14.     .Open
  15.  
  16.    Do While Not .EOF
  17.      Debug.Print UCase$(![LastName]) & ", " & ![FirstName]
  18.        .MoveNext
  19.    Loop
  20. End With
  21.  
  22. rs.Close
  23. Set rs = Nothing

 

Undefined function 'Nz' in expression

You SHOULD replace the Nz with an IIf(IsNull()) construct as it's prone to Errors for NOT reason.

See documentation for IIf and IsNull

When put together:Nz(expr, [valueifnull])
becomesIIf(IsNull(expr), valueifnull, valueifnotnull)

Examples
Default: Nz(tbl.A) => IIf(IsNull(tbl.A), '', tbl.A)
With fallback: Nz(tbl.A, tbl.B) => IIf(IsNull(tbl.A), tbl.B, tbl.A)