Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiselect Listbox Value error

Status
Not open for further replies.

Minkers

Technical User
Dec 15, 2004
70
US
I have a listbox that when using code to find out what the value is, it shows correctly the values selected. I have a code running on that lisbox that runs a recordset command. The value of the listbox in the code is always wrong. It seems to be random what value the number will be. The listbox has three columns, two hidden. The first columen is the ModelID, which is the number that is needed. It is also the bound column. Can anyone explain what might be the problem? Code Below.

Thanks in Advance!
Minkers.

Code:
Private Sub comSubmit_Click()
Set rs = New ADODB.Recordset
Dim varItem As Variant
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.ActiveConnection = CurrentProject.Connection

rs.Open "SELECT ECNID, Quantity, Phase, Workstation, " _
      & "UnitCost, PartID, ModelID, StandardOrOptionalID, " _
      & "PartAddDel " _
      & "FROM tblCost;"
For Each varItem In Me.lstModels.ItemsSelected
    varECNID = Me.ECNID
    rs.AddNew
    MsgBox varItem
    rs!ECNID = ECNID
    rs!Quantity = Quantity
    rs!Phase = Phase
    rs!Workstation = Workstation
    rs!UnitCost = UnitCost
    rs!PartID = PartID
    rs!ModelID = varItem
    rs!StandardOrOptionalID = StandardOrOptional
    rs!PartAddDel = PartAddDel
    Stop
    

    rs.Update
    i = i + 1
Next varItem
rs.Close
Set rs = Nothing
If i > 0 Then
    MsgBox i & " Models were updated", , "Done"
Else
    MsgBox "No models were chosen", , "No changes"
End If

End Sub
 
Replace this:
rs!ModelID = varItem
By this:
rs!ModelID = Me.lstModels.ItemData(varItem)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top