Stuck, Need Help w/ Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm getting now where with the code below, due to the fact that I don't know
what I'm doing. This code is in the DblClick event of listBox (lstRNnotesLU).
The listBox is on form frmRNnotes which is connected to my frmVisit by
fldVisitNo. I need to get the list item that is being dblclk'd into the
tblRNnotes with the fldVisitNo in as the child.

The list is on the frmRNnotes along with a continuos form contrlol that is
based a query of the table tblRNnotes. Pls help if you can. Thanks, Rob


Dim db As DAO.Database
Dim strSQL As String
Dim varItm As Variant

Set db = CurrentDb()
With Forms!frmRNnotes!lstRNnotesLU
For Each varItm In .ItemsSelected
strSQL = "INSERT INTO tblRNnotes () " & _
"VALUES('" & .ItemData(varItm) & "'"
db.Execute strSQL, dbFailOnError
Next varItm
End With
 
Rob, You have to tell it what column to insert the data into.

Change:

strSQL = "INSERT INTO tblRNnotes () " & _

to:

strSQL = "INSERT INTO tblRNnotes ([someFieldName]) " & _


HTH
Dale
 
This is what is happening now. I get the following error w/ the code below.
Can someone help me with figuring out how to insert the current VisitNo
(fldVisitNo) that is linked to RNnotes into the equation below. Thanks Robert

Error 3201 You cannot add or change a record because a related record is
required in table "tblVisit."


Dim db As DAO.Database
Dim strSQL As String
Dim varItm As Variant

Set db = CurrentDb()
With Forms!frmRNnotes!lstRNnotesLU
For Each varItm In .ItemsSelected
CurrentDb.Execute ("INSERT INTO tblRNnotes (fldRNnotes) " _
& "VALUES ('" & .ItemData(varItm) & "');"), dbFailOnError
Next varItm
End With

Debug.Print

Dale Fye said:
Rob, You have to tell it what column to insert the data into.

Change:

strSQL = "INSERT INTO tblRNnotes () " & _

to:

strSQL = "INSERT INTO tblRNnotes ([someFieldName]) " & _


HTH
Dale
--
Email address is not valid.
Please reply to newsgroup only.


RobUCSD said:
I'm getting now where with the code below, due to the fact that I don't know
what I'm doing. This code is in the DblClick event of listBox (lstRNnotesLU).
The listBox is on form frmRNnotes which is connected to my frmVisit by
fldVisitNo. I need to get the list item that is being dblclk'd into the
tblRNnotes with the fldVisitNo in as the child.

The list is on the frmRNnotes along with a continuos form contrlol that is
based a query of the table tblRNnotes. Pls help if you can. Thanks, Rob


Dim db As DAO.Database
Dim strSQL As String
Dim varItm As Variant

Set db = CurrentDb()
With Forms!frmRNnotes!lstRNnotesLU
For Each varItm In .ItemsSelected
strSQL = "INSERT INTO tblRNnotes () " & _
"VALUES('" & .ItemData(varItm) & "'"
db.Execute strSQL, dbFailOnError
Next varItm
End With
 
Robert,

I assume that you have a control on your form that contains the visit
number. I will also assume that this is a numeric value, not a string. Try

For Each varItm In .ItemsSelected
CurrentDb.Execute ("INSERT INTO tblRNnotes (fldVisitNo, fldRNnotes) " _
& "VALUES (" me.txt_VisitNo & ",'" &
..ItemData(varItm) & "');"), dbFailOnError
Next varItm

HTH
Dale

RobUCSD said:
This is what is happening now. I get the following error w/ the code
below.
Can someone help me with figuring out how to insert the current VisitNo
(fldVisitNo) that is linked to RNnotes into the equation below. Thanks
Robert

Error 3201 You cannot add or change a record because a related record is
required in table "tblVisit."


Dim db As DAO.Database
Dim strSQL As String
Dim varItm As Variant

Set db = CurrentDb()
With Forms!frmRNnotes!lstRNnotesLU
For Each varItm In .ItemsSelected
CurrentDb.Execute ("INSERT INTO tblRNnotes (fldRNnotes) " _
& "VALUES ('" & .ItemData(varItm) & "');"), dbFailOnError
Next varItm
End With

Debug.Print

Dale Fye said:
Rob, You have to tell it what column to insert the data into.

Change:

strSQL = "INSERT INTO tblRNnotes () " & _

to:

strSQL = "INSERT INTO tblRNnotes ([someFieldName]) " & _


HTH
Dale
--
Email address is not valid.
Please reply to newsgroup only.


RobUCSD said:
I'm getting now where with the code below, due to the fact that I don't
know
what I'm doing. This code is in the DblClick event of listBox
(lstRNnotesLU).
The listBox is on form frmRNnotes which is connected to my frmVisit by
fldVisitNo. I need to get the list item that is being dblclk'd into the
tblRNnotes with the fldVisitNo in as the child.

The list is on the frmRNnotes along with a continuos form contrlol that
is
based a query of the table tblRNnotes. Pls help if you can. Thanks, Rob


Dim db As DAO.Database
Dim strSQL As String
Dim varItm As Variant

Set db = CurrentDb()
With Forms!frmRNnotes!lstRNnotesLU
For Each varItm In .ItemsSelected
strSQL = "INSERT INTO tblRNnotes () " & _
"VALUES('" & .ItemData(varItm) & "'"
db.Execute strSQL, dbFailOnError
Next varItm
End With
 
Back
Top