I have a table named
tbl_Questions
with a column called Region
I have a total of 8 regions
I am attempting to set an Unbound multiselect listbox on a form called frm_DH
I need the user to be able to select and deselect any combination of 8 regions and the record to show in the splitform datasheet and update the questions table.
So far I can select the data but it does not populate the qry_DH nor the tbl_Questions and fails to save once the form is closed.
here is my code:
[Code/]
Private Sub cmd_lst_Region_ Click()
On Error GoTo PROC_ERR
'Declare items
Dim iItem As Integer
Dim Region As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
' Save the current record if it's not saved
If Me.Dirty = True Then
Me.Dirty = False
End If
' Open a Recordset based on the table
Set db = CurrentDb
Set rs = db.OpenRecordse t("tbl_Question s", dbOpenDynaset)
With Me!lst_Region
' Loop through all rows in the Listbox
For iItem = 0 To .ListCount - 1
Region = .Column(0, iItem)
' Determine whether this combination is currently
' in the table
rs.FindFirst "[ID] = " & Forms!frm_DH!ls t_Region & " ; " _
& "[Region] = " & lst_Region.AddI tem
If rs.NoMatch Then
' this item has not been added
If .Selected(iItem ) Then
' add it
rs.AddNew
rs!ID = Me.txt_ID
rs!lst_Region = lst_Region
rs.Update
End If
' if it wasn't selected, ignore it
Else
If Not .Selected(iItem ) Then
' delete this record if it's been deselected
rs.Delete
End If
' if it was selected, leave it alone
End If
Next iItem
End With
rs.Close
Set rs = Nothing
Set db = Nothing
PROC_EXIT:
Exit Sub
PROC_ERR:
MsgBox "Error " & Err.Number & " in cmdProcess_Clic k:" _
& vbCrLf & Err.Description
Resume PROC_EXIT
End Sub
[End_Code/]
I am sure I have messed this up royally in addition I am sure I am attempting to do the impossible.
thank you for any assistance and I hope I have offered enough information. I am using access 2007 at this time.
tbl_Questions
with a column called Region
I have a total of 8 regions
I am attempting to set an Unbound multiselect listbox on a form called frm_DH
I need the user to be able to select and deselect any combination of 8 regions and the record to show in the splitform datasheet and update the questions table.
So far I can select the data but it does not populate the qry_DH nor the tbl_Questions and fails to save once the form is closed.
here is my code:
[Code/]
Private Sub cmd_lst_Region_ Click()
On Error GoTo PROC_ERR
'Declare items
Dim iItem As Integer
Dim Region As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
' Save the current record if it's not saved
If Me.Dirty = True Then
Me.Dirty = False
End If
' Open a Recordset based on the table
Set db = CurrentDb
Set rs = db.OpenRecordse t("tbl_Question s", dbOpenDynaset)
With Me!lst_Region
' Loop through all rows in the Listbox
For iItem = 0 To .ListCount - 1
Region = .Column(0, iItem)
' Determine whether this combination is currently
' in the table
rs.FindFirst "[ID] = " & Forms!frm_DH!ls t_Region & " ; " _
& "[Region] = " & lst_Region.AddI tem
If rs.NoMatch Then
' this item has not been added
If .Selected(iItem ) Then
' add it
rs.AddNew
rs!ID = Me.txt_ID
rs!lst_Region = lst_Region
rs.Update
End If
' if it wasn't selected, ignore it
Else
If Not .Selected(iItem ) Then
' delete this record if it's been deselected
rs.Delete
End If
' if it was selected, leave it alone
End If
Next iItem
End With
rs.Close
Set rs = Nothing
Set db = Nothing
PROC_EXIT:
Exit Sub
PROC_ERR:
MsgBox "Error " & Err.Number & " in cmdProcess_Clic k:" _
& vbCrLf & Err.Description
Resume PROC_EXIT
End Sub
[End_Code/]
I am sure I have messed this up royally in addition I am sure I am attempting to do the impossible.
thank you for any assistance and I hope I have offered enough information. I am using access 2007 at this time.
Comment