I've been working on this darn problem for over a week can't figure it out. I am updating an older program from a DAO database to an Access 2000 ADO formatted database. I have a grid on a form (Microsoft Data Bound Grid Control 5.0 - SP-3: DBGrid32.OCX) which is attached to a data controller (Microsoft Data Bound List Control 5.0 - SP-3: DBList32.OCX). The controller is named datSub. The form has another data controller named datMain that controls the data on the main form.
I was able to successfully attach the data controller to the Access 2000 database. I converted all the code over to the ADO syntax. Everything in the program works fine except posting new records to the grid. I have a routine that looks up data and ads records to the data table the the data controller is hooked to. After the new records are created I try to refresh the grid and no records appear. If I close the form and reopen it, the new records are there. Additionally, If I move off of the main record and then go back to it, the records appear. If have the following code in my datMain reposition event:
'Restrict the line item information to a specific record number
datSub.RecordSource = "select * from CycleItem " & "where CycleItem.[Cycle Number] = '" & txtCycleNum.Text & "'" & " _
order by [Row Number], [Item Number], [Position] ASC"
datSub.Refresh
This is working perfectly. The routine that won't post data to the grid is as follows:
Private Sub GetStockData()
'Declare form variables
Dim sql1 As String
Dim sqlRow As String
Dim dbname As String
Dim db1 As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim rsRow As ADODB.Recordset
Dim stItemNum as string
Dim stSize As String
Dim inPosition As Integer
Dim cuValue As Currency
'Select database to use
dbname = "dcdata.mdb"
Set db1 = New ADODB.Connection
'Specify the connection string
db1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " & dbname
'Open Database
db1.Open
'Initiate the recordsets
Set rsRow = New ADODB.Recordset
Set rs1 = New ADODB.Recordset
'Define recordset to be used for data
sql1 = "select * from [Stock]"
sql1 = sql1 & "where [Row Number] = '" & stRow & "'"
sql1 = sql1 & " order by [Row Number], [Item Number] ASC"
rs1.Open sql1, db1, adOpenKeyset, adLockPessimistic, adCmdText
'Check for at least one record in database
If rs1.RecordCount > 0 Then
'Define recordset to be used for datasqlRow = "select * from [CycleItem]"
'Open recordset
rsRow.Open sqlRow, db1, adOpenKeyset, adLockPessimistic, adCmdText
'Go to first record
rs1.MoveFirst
Do While Not rs1.EOF
stItemNum = rs1![Item Number]
stSize = rs1![Size]
cuValue = rs1![Value]
inPosition = rs1![Position]
'Set the recordset to rsRow for all operations in the loop
With rsRow
.AddNew
![Cycle Number] = txtCycleNum.Text
![Row Number] = rs1![Row Number]
![Item Number] = rs1![Item Number]
!Size = rs1![Size]
!Position = inPosition
!Description = rs1![Description]
![System Quantity] = rs1![Quantity]
!Unit = rs1![Unit]
!Value = cuValue
![First Count] = 0
![First Variance] = 0
![Second Count] = 0
![Second Variance] = 0
.Update
End With
rs1.MoveNext
Loop
'Reset the data controller record source that is connected to the datagrid
datSub.RecordSource = "select * from CycleItem " & "where CycleItem.[Cycle Number] = '" & _
txtCycleNum.Text & "'" & " order by [Row Number], [Item Number], [Position] ASC"
'Post new data to grid
datSub.Refresh
Else
InUserResponse = MsgBox("No items were found.", vbOKOnly, "Record Check Check")
End If
'Reset recordsets and db
Set rs1 = Nothing
Set rsRow = Nothing
db1.Close
Exit Sub
I have confirmed that the new records are actually in the database table right after the routine is run. I have have tried switching the the Microsoft ADO Data Control 6.0 with the Microsoft DataGrid Control 6.0, and have the exact same issue. The routine use to work perfectly with the Access 97 DAO database. I'm sure it is just something I am not familiar with on the ADO version. Any help would be greatly appreciated!!! Once I get this figured out, I have to convert a bunch of other programs. Thanks!!!