R
RobUCSD
The following code was plucked from a previous post. I'm trying to implement
it in my app, but I'm very much the rookie coder and could use some help.
What I'm trying to do is create a record in a table when the user dblClks on
an item in my list box. With the code below I get a "variable not defined"
msg on the OpenRecordset. I'm not sure why. Additionally, when the record is
inserted into the table, I need it to add the current fldVisitNo into the
table along with the text (or fldRNnotesLuNo). Finally, my list is not a
multi-selection list, and I think this code is for a mult-selection lst. Any
help would be greatly appreciated.
Thanks,
Rob
Dim db As Database
Dim frm As Form, ctl As Control, tbl As TableDef
Dim varItm As Variant
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db(OpenRecordset, "tblRNnotes", dbOpenDnaset)
Set frm = Forms!frmqryRNnotes
Set ctl = frm!lstRNnotesLU
For Each varItm In ctl.ItemsSelected
With rst
..AddNew
!gl_code = ctl.ItemsSelected(varItm)
..Update
End With
Next varItm
rst.Close
Set db = Nothing
Set rst = Nothing
Set frm = Nothing
Set ctl = Nothing
End Sub
it in my app, but I'm very much the rookie coder and could use some help.
What I'm trying to do is create a record in a table when the user dblClks on
an item in my list box. With the code below I get a "variable not defined"
msg on the OpenRecordset. I'm not sure why. Additionally, when the record is
inserted into the table, I need it to add the current fldVisitNo into the
table along with the text (or fldRNnotesLuNo). Finally, my list is not a
multi-selection list, and I think this code is for a mult-selection lst. Any
help would be greatly appreciated.
Thanks,
Rob
Dim db As Database
Dim frm As Form, ctl As Control, tbl As TableDef
Dim varItm As Variant
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db(OpenRecordset, "tblRNnotes", dbOpenDnaset)
Set frm = Forms!frmqryRNnotes
Set ctl = frm!lstRNnotesLU
For Each varItm In ctl.ItemsSelected
With rst
..AddNew
!gl_code = ctl.ItemsSelected(varItm)
..Update
End With
Next varItm
rst.Close
Set db = Nothing
Set rst = Nothing
Set frm = Nothing
Set ctl = Nothing
End Sub