This code is in the dblck event of a lstBox called lstRNnotes. When the user
dblclks on an item I need to store it the tblRNnotes with the fldVisitNo that
is on frmRNnotes that is linked to frmVisit by fldVisitNo.
lstVisit gets it's data from tblRNnotesLU which has canned nursing notes
that the nurse can insert into the tblRNnotes. Hope that's clear.
Ok... try this.
Set db = CurrentDb()
With Forms!frmRNnotes!lstRNnotesLU
For Each varItm In .ItemsSelected
strSQL = "INSERT INTO tblRNnotes (fldRNnotes, fldVisitNo) " & _
"VALUES (" & Chr(34) & .ItemData(varItm) & Chr(34) "," & _
Me.fldVisitNo & ");"
db.Execute strSQL, dbFailOnError
Next varItm
End With
Assuming that the ItemData is the text string that you want inserted,
and that you want to insert the VisitNo from the current form control
or field named fldVisitNo into tblRNnotes' fldVisitNo, this should
work. You can step through the code and view the value of strSQL prior
to the Execute statement; it might contain something like
INSERT INTO tblRNnotes (fldRNnotes, fldVisitNo) VALUES("Patient left
the OR in good condition", 3125);
indicating that the patient swept the floor, washed down the operating
table, etc.
Note that I do NOT know the datatype of fldVisitNo - if it's text,
you'll need quotes (Chr(34) is a " character) around it too; nor do I
know the bound column of lstRNnotesLU, I'm assuming that it's a Text
field that you want actually inserted into tblRNnotes. If it's a MEMO
field that you want to insert this will *not* work since a Memo in a
Listbox will be truncated to 255 bytes.
John W. Vinson [MVP]