I am having problems assigning the recordset values to a tabular form with unbound boxes. I have assigned the values eg. frm1.txt_Operator(X) = rst1(0) and put this in a loop as below..it give me a error 451 and if I put it outside a loop eg. frm1.txt_Operator = rst1(0)
then it shows only the last record.. How can I assign all the values of the recordset from the loop to the textboxes
Option Compare Database
Private Sub Search_Click()
Dim int1 As Integer
Dim int2 As Long
Dim int3 As Long
Dim cnn1 As ADODB.Connection
Dim rst1 As Recordset
Dim str1 As String
Dim str_op As String
Dim str_cent As String
Dim str_adv As String
Dim X As Integer
X = 1
Set cnn1 = New ADODB.Connection
cnn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and Settings\Administrator\My Documents\Skills Assessment file" & _
"\SAR.mdb;"
Set rst1 = New ADODB.Recordset
rst1.CursorType = adOpenKeyset
rst1.LockType = adLockOptimistic
rst1.CursorLocation = adUseClient
'Open recordset based on orders in 1998 for
'frmSimpleUnboundForm
rst1.Open "SELECT a.Operator, a.Center, " & _
"a.Photoshop FROM [Main-TG] as a where a.photoshop Is Not Null ;", cnn1
'Print record with revised Quantity field
Debug.Print rst1(0), rst1(1), rst1(2),
str1 = "frm_skill_tz"
DoCmd.OpenForm str1
Set frm1 = Forms(str1)
Set frm1.Recordset = rst1
Do While Not rst1.EOF
frm1.txt_Operator(X) = rst1(0)
frm1.txt_Center(X) = rst1(1)
frm1.txt_adv(X) = rst1(2)
Debug.Print rst1(0), rst1(1), rst1(2)
rst1.MoveNext
X = X + 1
Loop
'Clean up objects
rst1.Close
cnn1.Close
Set rst1 = Nothing
Set cnn1 = Nothing
End Sub
Regards
Tinku
then it shows only the last record.. How can I assign all the values of the recordset from the loop to the textboxes
Option Compare Database
Private Sub Search_Click()
Dim int1 As Integer
Dim int2 As Long
Dim int3 As Long
Dim cnn1 As ADODB.Connection
Dim rst1 As Recordset
Dim str1 As String
Dim str_op As String
Dim str_cent As String
Dim str_adv As String
Dim X As Integer
X = 1
Set cnn1 = New ADODB.Connection
cnn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and Settings\Administrator\My Documents\Skills Assessment file" & _
"\SAR.mdb;"
Set rst1 = New ADODB.Recordset
rst1.CursorType = adOpenKeyset
rst1.LockType = adLockOptimistic
rst1.CursorLocation = adUseClient
'Open recordset based on orders in 1998 for
'frmSimpleUnboundForm
rst1.Open "SELECT a.Operator, a.Center, " & _
"a.Photoshop FROM [Main-TG] as a where a.photoshop Is Not Null ;", cnn1
'Print record with revised Quantity field
Debug.Print rst1(0), rst1(1), rst1(2),
str1 = "frm_skill_tz"
DoCmd.OpenForm str1
Set frm1 = Forms(str1)
Set frm1.Recordset = rst1
Do While Not rst1.EOF
frm1.txt_Operator(X) = rst1(0)
frm1.txt_Center(X) = rst1(1)
frm1.txt_adv(X) = rst1(2)
Debug.Print rst1(0), rst1(1), rst1(2)
rst1.MoveNext
X = X + 1
Loop
'Clean up objects
rst1.Close
cnn1.Close
Set rst1 = Nothing
Set cnn1 = Nothing
End Sub
Regards
Tinku