Stuck, Need Help w/ Code

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
 
G

Guest

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
 
G

Guest

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
 
D

Dale Fye

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
 

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

Similar Threads

Getting no where 1
Need help w/ syntax! 3
Syntax error 14
Erro 3201 3
Run-time Error '2480' 3
Code Help 10
combo box - Help! 2
saving listbox choices to a table 2

Top