S
swedbera
Could someone please take a look at my code and tell me why it only works
intermittently? I cannot figure it out and need another pair of eyes to take
a look. I would think that it would either work or not. I have two other
forms in my database that do the same thing and they both work all of the
time. The difference between the code behind those forms and this form is
that the reference to the index is set differently and the primary key in
both of the other forms is the field that is being updated through code. If
that is the problem, I'm not sure how to fix it.
Thanks,
Arlene
Dim rst As New ADODB.Recordset
Dim cnn As ADODB.Connection
Dim msg As String, varNumber As Variant
Set cnn = CurrentProject.Connection
' In other form's code, this is set to rst.Index = "PrimaryKey"
rst.Index = "SupId"
rst.Open "tblSite", cnn, adOpenStatic, adLockOptimistic, adCmdTableDirect
'Set up the For Each loop throught the collection
For Each varNumber In Me.lstSites.ItemsSelected
rst.Seek Me.lstSites.ItemData(varNumber), adSeekFirstEQ
rst!SupID = Me.cboNewSupID
rst.Update
Next
Me.cboCurrentSupId = Me.cboNewSupID
Me.cboNewSupID = Null
strsql = "SELECT tblSite.SupID, tblSupervisor.Supervisor,
tblSite.SiteCode, tblSite.SiteType, tblSite.AcctName FROM tblSupervisor INNER
JOIN tblSite ON tblSupervisor.SupID = tblSite.SupID WHERE
[tblSite].[SupId]='" & Me.cboCurrentSupId & "' ORDER BY [tblSite].[AcctName];
"
Me.lstSites.RowSource = strsql
rst.Close
intermittently? I cannot figure it out and need another pair of eyes to take
a look. I would think that it would either work or not. I have two other
forms in my database that do the same thing and they both work all of the
time. The difference between the code behind those forms and this form is
that the reference to the index is set differently and the primary key in
both of the other forms is the field that is being updated through code. If
that is the problem, I'm not sure how to fix it.
Thanks,
Arlene
Dim rst As New ADODB.Recordset
Dim cnn As ADODB.Connection
Dim msg As String, varNumber As Variant
Set cnn = CurrentProject.Connection
' In other form's code, this is set to rst.Index = "PrimaryKey"
rst.Index = "SupId"
rst.Open "tblSite", cnn, adOpenStatic, adLockOptimistic, adCmdTableDirect
'Set up the For Each loop throught the collection
For Each varNumber In Me.lstSites.ItemsSelected
rst.Seek Me.lstSites.ItemData(varNumber), adSeekFirstEQ
rst!SupID = Me.cboNewSupID
rst.Update
Next
Me.cboCurrentSupId = Me.cboNewSupID
Me.cboNewSupID = Null
strsql = "SELECT tblSite.SupID, tblSupervisor.Supervisor,
tblSite.SiteCode, tblSite.SiteType, tblSite.AcctName FROM tblSupervisor INNER
JOIN tblSite ON tblSupervisor.SupID = tblSite.SupID WHERE
[tblSite].[SupId]='" & Me.cboCurrentSupId & "' ORDER BY [tblSite].[AcctName];
"
Me.lstSites.RowSource = strsql
rst.Close