I would like to loop through a recordset in Access VBA and extract the values of a variable as a string in VBA. This won't work:
Sub test()
Dim rs As DAO.Recordset
Dim m As String
Set rs = CurrentDb.openrecordset("myTable")
If Not (rs.EOF And rs.bof) Then
rs.movefirst
Do Until rs.EOF
debug.print rs!myField 'works
MsgBox rs!myField 'doesn't work
rs.movenext
Loop
End If
rs.Close
End Sub
It gives me an error with the msgbox about nulls, but it works fine for debug.print. I can't seem to extract the rs!myField
into a VBA string variable. The character variable in the table contains null values, but I should be able to still work with it.
myStr = rs.Fields("MyField").value
Then use myStr it in your MsgBox. – Ryan WildrymyStr
, butdebug.print
works with your code FWIW. – Carl