MultiSelect List Box To Table

F

FlyBoy

I've read all the posts, went to all the suggested sites, and tried all the
sample code. I know I'm dense, but I still can't get a multiselct list box
to store values in the table I want.

Using A2003 on XPPro, I have one table, tblImpacts linked 1toMany to another
table, tblImpactedProjects via the tblImpacts PK, EntryID (autonumber) to
tblImpactedProjects EntryID (number). If I only have the ImpactedProject
field in the tblImpactedProjects, it works fine. If I have omre than one
field in the table, it errors out.

The main entry form frmImpactEntry is bound to tblImpacts. This is the code
I'm trying to use:

Private Sub lboxImpactedProject_LostFocus()

Dim rst As Recordset
Dim strItems As String
Dim strItems2 As String
Dim LstItem As String
Dim intCurrentRow As Integer


Set rst = CurrentDb().OpenRecordset("ImpactedProject")
' Get the list box selections
For intCurrentRow = 0 To lboxImpactedProject.ListCount - 1
'Is selected?
If lboxImpactedProject.Selected(intCurrentRow) Then
'Get value
LstItem = lboxImpactedProject.Column(0, intCurrentRow)
'Add to Table
rst.AddNew
rst("ImpactedProject") = LstItem
rst.Update
'Build list for msgbox
'strItems = strItems & LstItem & vbCrLf

End If
Next intCurrentRow
'MsgBox " You Have Selected " & vbCrLf & strItems & vbCrLf & "Open the
ListSelectResults table"
rst.Close

End Sub

Thanks in Advance
 
G

Graham Mandeno

Hi FlyBoy

You say "it errors out", but what is the error?

Your code is only writing a single field (ImpactedProject) to the
tblImpactedProjects table, but you say it has a foreign key named "EntryID".
This will presumably be a required field, so you should be writing that one
as well.
 
G

Guest

Thanks for the reply. I've come up with a different solution.

Graham Mandeno said:
Hi FlyBoy

You say "it errors out", but what is the error?

Your code is only writing a single field (ImpactedProject) to the
tblImpactedProjects table, but you say it has a foreign key named "EntryID".
This will presumably be a required field, so you should be writing that one
as well.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

FlyBoy said:
I've read all the posts, went to all the suggested sites, and tried all
the
sample code. I know I'm dense, but I still can't get a multiselct list box
to store values in the table I want.

Using A2003 on XPPro, I have one table, tblImpacts linked 1toMany to
another
table, tblImpactedProjects via the tblImpacts PK, EntryID (autonumber) to
tblImpactedProjects EntryID (number). If I only have the ImpactedProject
field in the tblImpactedProjects, it works fine. If I have omre than one
field in the table, it errors out.

The main entry form frmImpactEntry is bound to tblImpacts. This is the
code
I'm trying to use:

Private Sub lboxImpactedProject_LostFocus()

Dim rst As Recordset
Dim strItems As String
Dim strItems2 As String
Dim LstItem As String
Dim intCurrentRow As Integer


Set rst = CurrentDb().OpenRecordset("ImpactedProject")
' Get the list box selections
For intCurrentRow = 0 To lboxImpactedProject.ListCount - 1
'Is selected?
If lboxImpactedProject.Selected(intCurrentRow) Then
'Get value
LstItem = lboxImpactedProject.Column(0, intCurrentRow)
'Add to Table
rst.AddNew
rst("ImpactedProject") = LstItem
rst.Update
'Build list for msgbox
'strItems = strItems & LstItem & vbCrLf

End If
Next intCurrentRow
'MsgBox " You Have Selected " & vbCrLf & strItems & vbCrLf & "Open the
ListSelectResults table"
rst.Close

End Sub

Thanks in Advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top