A
Anand
Hello,
I have a Multi Select list box in a Form (A2k). The following is the Code I
have written. The Code works fine if only one item is selected in the List
Box. When two or more lines are selected the first pass through the "For Each
varItm ... Next varItm" works fine. The problem is in the second pass - I get
an error "Item not found in this collection" at the "rstMtrls_Add!fkPOMainID
= rst!fkPOMainID" line. The subsequent lines also display the same error in
Break mode. Cant seem to figure out why. Any help?
TIA
Anand
Set dbs = CurrentDb
Set ctl = Me.lstPOItems
For Each varItm In ctl.ItemsSelected
intMaterialsID = ctl.ItemData(varItm)
intRevNo = ctl.Column(1, varItm)
stSQL = "SELECT tblPOMaterials.fkPOMainID, tblPOMaterials.ItemNo
FROM tblPOMaterials WHERE tblPOMaterials.pkMaterialsID = " & intMaterialsID &
"
AND tblPOMaterials.RevisionNo = " & intRevNo & ""
Set rst = dbs.OpenRecordset(stSQL)
With rst
Set rstMtrls_Add = dbs.OpenRecordset("tblPOMaterials")
With rstMtrls_Add
rstMtrls_Add.AddNew
rstMtrls_Add!pkMaterialsID = intMaterialsID
rstMtrls_Add!RevisionNo = intRevNo + 1
rstMtrls_Add!fkPOMainID = rst!fkPOMainID
rstMtrls_Add!ItemNo = rst!ItemNo
rstMtrls_Add.Update
End With
End With
Next varItm
I have a Multi Select list box in a Form (A2k). The following is the Code I
have written. The Code works fine if only one item is selected in the List
Box. When two or more lines are selected the first pass through the "For Each
varItm ... Next varItm" works fine. The problem is in the second pass - I get
an error "Item not found in this collection" at the "rstMtrls_Add!fkPOMainID
= rst!fkPOMainID" line. The subsequent lines also display the same error in
Break mode. Cant seem to figure out why. Any help?
TIA
Anand
Set dbs = CurrentDb
Set ctl = Me.lstPOItems
For Each varItm In ctl.ItemsSelected
intMaterialsID = ctl.ItemData(varItm)
intRevNo = ctl.Column(1, varItm)
stSQL = "SELECT tblPOMaterials.fkPOMainID, tblPOMaterials.ItemNo
FROM tblPOMaterials WHERE tblPOMaterials.pkMaterialsID = " & intMaterialsID &
"
AND tblPOMaterials.RevisionNo = " & intRevNo & ""
Set rst = dbs.OpenRecordset(stSQL)
With rst
Set rstMtrls_Add = dbs.OpenRecordset("tblPOMaterials")
With rstMtrls_Add
rstMtrls_Add.AddNew
rstMtrls_Add!pkMaterialsID = intMaterialsID
rstMtrls_Add!RevisionNo = intRevNo + 1
rstMtrls_Add!fkPOMainID = rst!fkPOMainID
rstMtrls_Add!ItemNo = rst!ItemNo
rstMtrls_Add.Update
End With
End With
Next varItm