This is driving me NUTS!!!!!!!!
I have the following code that works great ..... with 2 small exceptions
NOTES:
For this case I will say the user has selected ITEMS # 2 and 4
1. ![fkCSMGoalsID] = varItem + 1 ----I shouldn't have to put the +1, but it I don't it stores 1 and 3--hmmm
2. The rst shows the following results: 2, 2 and 4-- adding 1 extra item that WASN'T selected
WHY??????
I'm not overly concerned with #1, just curious..but need to resolve #2 in a very bad way....
The only other code that's attached to the lstbox is:
Which has nothing to do with the process.
Thanks in advance.
I have the following code that works great ..... with 2 small exceptions
Code:
Private Sub lstGoals_AfterUpdate()
Dim ctl As Control
Dim varItem As Variant
Dim sTemp As String
Dim DB As Database
Dim rst As Recordset
Dim iRN As Integer
Set ctl = Me.lstGoals ' Name of the Listbox
Set DB = CurrentDb
Set rst = Nothing
Set rst = DB.OpenRecordset("tbOpenGoals", dbOpenDynaset)
iRN = Forms![Member Data Entry]![RecordNo]
'For each item in the list box we are going to append each one with the
'respective project # to tbOpenGoals then we are going to combine each
'item together in one field
For Each varItem In ctl.ItemsSelected
With rst
.AddNew
![fkCSMGoalsID] = varItem + 1
![fkRecordNo] = iRN
.Update
End With
Next varItem
rst.Requery
rst.Close
DB.Close
'Need to do something with the remaining space and comma
For Each varItem In ctl.ItemsSelected
sTemp = sTemp & ctl.ItemData(varItem) & ", " 'Adds the comma and space to the string
Next varItem
If sTemp = "" Then
Else
'Remove the last comma and space
sTemp = Left$(sTemp, Len(sTemp) - 2)
End If
'This part puts the string of information into the field named tOpenGoals ***
Me!tOpenGoals = sTemp
End Sub
NOTES:
For this case I will say the user has selected ITEMS # 2 and 4
1. ![fkCSMGoalsID] = varItem + 1 ----I shouldn't have to put the +1, but it I don't it stores 1 and 3--hmmm
2. The rst shows the following results: 2, 2 and 4-- adding 1 extra item that WASN'T selected
WHY??????
I'm not overly concerned with #1, just curious..but need to resolve #2 in a very bad way....
The only other code that's attached to the lstbox is:
Code:
Me.[Data Entry].SetFocus
pgOpenGoals.Visible = False
Me.Requery
Which has nothing to do with the process.
Thanks in advance.