Below is code I am using to insert data into a table an dthen update the est_id.
It works fine for the last record in the loop but the others in the loop are not being updated by the bottom piece of code.
Anybody know what I am missing
Do While Not rstmat.EOF
Debug.Print rstmat!est_id
Debug.Print rstmat.RecordCount
With rstmat
' myestid = !est_id
mymat = !mat_desc
.MoveNext
End With
With rstmat3
.AddNew
' !est_id = myestid
!mat_desc = mymat
.Update
.MoveNext
End With
Set frmEst = Me!fsubEstDets.Form
Dim rstmat2 As ADODB.Recordset
'Open a connection
Set cnn = New ADODB.Connection
str = "Provider=SQLOLEDB;Data Source=SBS;" & _
"Initial Catalog=Test ;User Id=SQLACCESS;Password=suer;"
cnn.Open str
Set rstmat2 = New ADODB.Recordset
strsql1 = "SQLACCESS.tblctmat "
rstmat2.Open strsql1, cnn, adOpenKeyset, adLockOptimistic, adCmdTable
Set rstest = New ADODB.Recordset
strsql = "SQLACCESS.tblctest"
rstest.Open strsql, cnn, adOpenKeyset, adLockOptimistic, adCmdTable
With rstest
.MoveLast
myestid = !est_id
End With
With rstmat2
.MoveLast
mynewid = !Matid
End With
Debug.Print mynewid
Dim sql2 As String
sql2 = " UPDATE SQLACCESS.tblctmat Set est_id = " & myestid & _
" WHERE matid = " & mynewid
Debug.Print est_id
Debug.Print "MYNEWID"; mynewid
'DoCmd.RunCommand acCmdSaveRecord
rstmat2.Close
Loop
It works fine for the last record in the loop but the others in the loop are not being updated by the bottom piece of code.
Anybody know what I am missing
Do While Not rstmat.EOF
Debug.Print rstmat!est_id
Debug.Print rstmat.RecordCount
With rstmat
' myestid = !est_id
mymat = !mat_desc
.MoveNext
End With
With rstmat3
.AddNew
' !est_id = myestid
!mat_desc = mymat
.Update
.MoveNext
End With
Set frmEst = Me!fsubEstDets.Form
Dim rstmat2 As ADODB.Recordset
'Open a connection
Set cnn = New ADODB.Connection
str = "Provider=SQLOLEDB;Data Source=SBS;" & _
"Initial Catalog=Test ;User Id=SQLACCESS;Password=suer;"
cnn.Open str
Set rstmat2 = New ADODB.Recordset
strsql1 = "SQLACCESS.tblctmat "
rstmat2.Open strsql1, cnn, adOpenKeyset, adLockOptimistic, adCmdTable
Set rstest = New ADODB.Recordset
strsql = "SQLACCESS.tblctest"
rstest.Open strsql, cnn, adOpenKeyset, adLockOptimistic, adCmdTable
With rstest
.MoveLast
myestid = !est_id
End With
With rstmat2
.MoveLast
mynewid = !Matid
End With
Debug.Print mynewid
Dim sql2 As String
sql2 = " UPDATE SQLACCESS.tblctmat Set est_id = " & myestid & _
" WHERE matid = " & mynewid
Debug.Print est_id
Debug.Print "MYNEWID"; mynewid
'DoCmd.RunCommand acCmdSaveRecord
rstmat2.Close
Loop