Dim adConn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
Dim strName As String
adConn.Open "Data Source=(local);Initial Catalog=Test;User ID=<UID>;Password=<strong password>"
' Inserting through the connection object always removes padding because
' the table was created with ANSI_PADDING off.
strSQL = "insert into TestPadOff values('" & "John " & "')"
adConn.Execute strSQL
' Inserting through the Recordset object always preserves padding,
' regardless of the 'SET ANSI_PADDING OFF' setting on the Connection object.
adConn.Execute "set ansi_padding off"
'rs.cursorlocation = adUseClient
rs.Open "select * from TestPadOff", adConn, adOpenDynamic, adLockOptimistic
rs.AddNew
rs.Fields(0).Value = "Mike "
rs.Update
rs.MoveLast
strName = rs.Fields(0).Value
Debug.Print rs.Fields(0).Value & " " & CStr(Len(strName))
rs.Close
adConn.Close
Set rs = Nothing
Set adConn = Nothing
End Sub