Hello,
I trying to create an adodb record set, set recordset as the form recordset then bind one of the fields to a text box. When I ran the code it apparently worked because the navigation showed that there were seven records, but the text box I tried to bind the field to showed # error. Can someone explain to me what I doing wrong?
Code:
Set MyCnn = New ADODB.Connection
Set MyCnn = CurrentProject.AccessConnection
Dim rst As New ADODB.Recordset
rst.Fields.Append "Field1", adVarChar, 50
rst.Fields.Append "Field2", adVarChar, 50
rst.Fields.Refresh
'Create Recordset
rst.Open
'Add rows into recordset
rst.AddNew Array("field1", "field2"), Array(" A", "val1")
rst.AddNew Array("field1", "field2"), Array("string2", "val2")
rst.AddNew Array("field1", "field2"), Array("string2", "val2")
rst.AddNew Array("field1", "field2"), Array("string2", "val2")
rst.AddNew Array("field1", "field2"), Array("string2", "val2")
rst.AddNew Array("field1", "field2"), Array("string2", "val2")
rst.AddNew Array("field1", "field2"), Array("string2", "val2")
Set Me.Recordset = rst
'Me.txt1.ControlSource = "=[" & rst.Fields(0).Name & "]"
rst.MoveFirst
MsgBox rst.Fields(0).Name 'This shows the field value of the second record
'when I bind the field I get #Error, I get the same result when I set the control source to field1 in design view
Me.txt1.ControlSource = "=[" & rst.Fields(0).Name & "]"