Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: insert into

Geek News

insert into
short 11/14/2008 3:19:01 PM
I have a database that the users want to have a seperate table that holds the
primary keys of two other tables. So I create a table with both tables
primary keys in it:
Software_Node
NodeID
SoftwareID
(made both pk both numbers)
which is connected to the Software and Node tables by their pk's.

Now on the node form I have it where the user selects the software, and then
enters the node and then pressed a button to add the node which is supposed
to put in the PK's of the tables. So this is my code: (I posted this a few
days ago, but am now getting an error)

Private Sub cmdNode_Click()
Dim NodeID As Integer
Dim SoftwareID As Integer
NodeID = ID
SoftwareID = "SELECT Software.[ID] FROM Software where Software.[Name] = '"
+ cmbSoftware.Value + " AND ServerID = '" + ServerID = "';"

Dim sql As String

sql = "INSERT INTO Node_Software([NodeID], [SoftwareID]) VALUES ("" &
NodeID & "", "" & SoftwareID & "")"

MsgBox ("You have added a node")
DoCmd.RunSQL sql

End Sub

I keep getting an error message that MS Access can't append all the records
in the appened query.. set 1 field(s) to Null due to conversion failure

anyone have any idea what I did wrong?



Re: insert into
"Ken Snell \(MVP\)" <kthsneisllis9[ at ]ncoomcastt.renaetl> 11/14/2008 4:44:24 PM
SoftwareID is a string variable, which is being put into the SoftwareID
field, so I assume that the SoftwareID field is a text field. Therefore, you
must delimit the string text with " characters so that the insert query will
recognize the data as text:

sql = "INSERT INTO Node_Software([NodeID], [SoftwareID]) VALUES ("" &
NodeID & "", """" & SoftwareID & """")"

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/



"short" <short[ at ]discussions.microsoft.com> wrote in message
news:010662AD-37A3-4914-AA0D-684EE1DC6BDA[ at ]microsoft.com...
[Quoted Text]
>I have a database that the users want to have a seperate table that holds
>the
> primary keys of two other tables. So I create a table with both tables
> primary keys in it:
> Software_Node
> NodeID
> SoftwareID
> (made both pk both numbers)
> which is connected to the Software and Node tables by their pk's.
>
> Now on the node form I have it where the user selects the software, and
> then
> enters the node and then pressed a button to add the node which is
> supposed
> to put in the PK's of the tables. So this is my code: (I posted this a few
> days ago, but am now getting an error)
>
> Private Sub cmdNode_Click()
> Dim NodeID As Integer
> Dim SoftwareID As Integer
> NodeID = ID
> SoftwareID = "SELECT Software.[ID] FROM Software where Software.[Name] =
> '"
> + cmbSoftware.Value + " AND ServerID = '" + ServerID = "';"
>
> Dim sql As String
>
> sql = "INSERT INTO Node_Software([NodeID], [SoftwareID]) VALUES ("" &
> NodeID & "", "" & SoftwareID & "")"
>
> MsgBox ("You have added a node")
> DoCmd.RunSQL sql
>
> End Sub
>
> I keep getting an error message that MS Access can't append all the
> records
> in the appened query.. set 1 field(s) to Null due to conversion failure
>
> anyone have any idea what I did wrong?
>
>
>


Re: insert into
short 11/14/2008 4:59:01 PM
by text field does that include numbers?

"Ken Snell (MVP)" wrote:

[Quoted Text]
> SoftwareID is a string variable, which is being put into the SoftwareID
> field, so I assume that the SoftwareID field is a text field. Therefore, you
> must delimit the string text with " characters so that the insert query will
> recognize the data as text:
>
> sql = "INSERT INTO Node_Software([NodeID], [SoftwareID]) VALUES ("" &
> NodeID & "", """" & SoftwareID & """")"
>
> --
>
> Ken Snell
> <MS ACCESS MVP>
> http://www.accessmvp.com/KDSnell/
>
>
>
> "short" <short[ at ]discussions.microsoft.com> wrote in message
> news:010662AD-37A3-4914-AA0D-684EE1DC6BDA[ at ]microsoft.com...
> >I have a database that the users want to have a seperate table that holds
> >the
> > primary keys of two other tables. So I create a table with both tables
> > primary keys in it:
> > Software_Node
> > NodeID
> > SoftwareID
> > (made both pk both numbers)
> > which is connected to the Software and Node tables by their pk's.
> >
> > Now on the node form I have it where the user selects the software, and
> > then
> > enters the node and then pressed a button to add the node which is
> > supposed
> > to put in the PK's of the tables. So this is my code: (I posted this a few
> > days ago, but am now getting an error)
> >
> > Private Sub cmdNode_Click()
> > Dim NodeID As Integer
> > Dim SoftwareID As Integer
> > NodeID = ID
> > SoftwareID = "SELECT Software.[ID] FROM Software where Software.[Name] =
> > '"
> > + cmbSoftware.Value + " AND ServerID = '" + ServerID = "';"
> >
> > Dim sql As String
> >
> > sql = "INSERT INTO Node_Software([NodeID], [SoftwareID]) VALUES ("" &
> > NodeID & "", "" & SoftwareID & "")"
> >
> > MsgBox ("You have added a node")
> > DoCmd.RunSQL sql
> >
> > End Sub
> >
> > I keep getting an error message that MS Access can't append all the
> > records
> > in the appened query.. set 1 field(s) to Null due to conversion failure
> >
> > anyone have any idea what I did wrong?
> >
> >
> >
>
>
>
Re: insert into
"Ken Snell \(MVP\)" <kthsneisllis9[ at ]ncoomcastt.renaetl> 11/14/2008 5:30:05 PM
A text field is one where the Data Type property of the field in the table
is Text or Memo. A Text field can contain numeric values, but they are not
numbers, they are characters that look like numbers.

I see that I misread your original post. SoftwareID is dim'd as an Integer,
not a Text -- my mistake.

Are you sure that ID field is not NULL when your code runs?

What are the Data Type properties of the two fields in the Node_Software
table?

Also, the error message suggests that it did add the new record, but that
one field was given a NULL value. Which field is being assigned NULL by the
query when it runs and gives you the error? Look at the table after you run
the query and see.

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


"short" <short[ at ]discussions.microsoft.com> wrote in message
news:1BD37B2B-55AB-478E-830F-1F2B94C330A4[ at ]microsoft.com...
[Quoted Text]
> by text field does that include numbers?
>
> "Ken Snell (MVP)" wrote:
>
>> SoftwareID is a string variable, which is being put into the SoftwareID
>> field, so I assume that the SoftwareID field is a text field. Therefore,
>> you
>> must delimit the string text with " characters so that the insert query
>> will
>> recognize the data as text:
>>
>> sql = "INSERT INTO Node_Software([NodeID], [SoftwareID]) VALUES ("" &
>> NodeID & "", """" & SoftwareID & """")"
>>
>> --
>>
>> Ken Snell
>> <MS ACCESS MVP>
>> http://www.accessmvp.com/KDSnell/
>>
>>
>>
>> "short" <short[ at ]discussions.microsoft.com> wrote in message
>> news:010662AD-37A3-4914-AA0D-684EE1DC6BDA[ at ]microsoft.com...
>> >I have a database that the users want to have a seperate table that
>> >holds
>> >the
>> > primary keys of two other tables. So I create a table with both tables
>> > primary keys in it:
>> > Software_Node
>> > NodeID
>> > SoftwareID
>> > (made both pk both numbers)
>> > which is connected to the Software and Node tables by their pk's.
>> >
>> > Now on the node form I have it where the user selects the software, and
>> > then
>> > enters the node and then pressed a button to add the node which is
>> > supposed
>> > to put in the PK's of the tables. So this is my code: (I posted this a
>> > few
>> > days ago, but am now getting an error)
>> >
>> > Private Sub cmdNode_Click()
>> > Dim NodeID As Integer
>> > Dim SoftwareID As Integer
>> > NodeID = ID
>> > SoftwareID = "SELECT Software.[ID] FROM Software where Software.[Name]
>> > =
>> > '"
>> > + cmbSoftware.Value + " AND ServerID = '" + ServerID = "';"
>> >
>> > Dim sql As String
>> >
>> > sql = "INSERT INTO Node_Software([NodeID], [SoftwareID]) VALUES ("" &
>> > NodeID & "", "" & SoftwareID & "")"
>> >
>> > MsgBox ("You have added a node")
>> > DoCmd.RunSQL sql
>> >
>> > End Sub
>> >
>> > I keep getting an error message that MS Access can't append all the
>> > records
>> > in the appened query.. set 1 field(s) to Null due to conversion failure
>> >
>> > anyone have any idea what I did wrong?
>> >
>> >
>> >
>>
>>
>>


Re: insert into
short 11/14/2008 6:39:06 PM
Both fields in the Node_software table are number fields. When I run the
query and look in the Node_software table, I get the nodeId number but no
softwareID

"Ken Snell (MVP)" wrote:

[Quoted Text]
> A text field is one where the Data Type property of the field in the table
> is Text or Memo. A Text field can contain numeric values, but they are not
> numbers, they are characters that look like numbers.
>
> I see that I misread your original post. SoftwareID is dim'd as an Integer,
> not a Text -- my mistake.
>
> Are you sure that ID field is not NULL when your code runs?
>
> What are the Data Type properties of the two fields in the Node_Software
> table?
>
> Also, the error message suggests that it did add the new record, but that
> one field was given a NULL value. Which field is being assigned NULL by the
> query when it runs and gives you the error? Look at the table after you run
> the query and see.
>
> --
>
> Ken Snell
> <MS ACCESS MVP>
> http://www.accessmvp.com/KDSnell/
>
>
> "short" <short[ at ]discussions.microsoft.com> wrote in message
> news:1BD37B2B-55AB-478E-830F-1F2B94C330A4[ at ]microsoft.com...
> > by text field does that include numbers?
> >
> > "Ken Snell (MVP)" wrote:
> >
> >> SoftwareID is a string variable, which is being put into the SoftwareID
> >> field, so I assume that the SoftwareID field is a text field. Therefore,
> >> you
> >> must delimit the string text with " characters so that the insert query
> >> will
> >> recognize the data as text:
> >>
> >> sql = "INSERT INTO Node_Software([NodeID], [SoftwareID]) VALUES ("" &
> >> NodeID & "", """" & SoftwareID & """")"
> >>
> >> --
> >>
> >> Ken Snell
> >> <MS ACCESS MVP>
> >> http://www.accessmvp.com/KDSnell/
> >>
> >>
> >>
> >> "short" <short[ at ]discussions.microsoft.com> wrote in message
> >> news:010662AD-37A3-4914-AA0D-684EE1DC6BDA[ at ]microsoft.com...
> >> >I have a database that the users want to have a seperate table that
> >> >holds
> >> >the
> >> > primary keys of two other tables. So I create a table with both tables
> >> > primary keys in it:
> >> > Software_Node
> >> > NodeID
> >> > SoftwareID
> >> > (made both pk both numbers)
> >> > which is connected to the Software and Node tables by their pk's.
> >> >
> >> > Now on the node form I have it where the user selects the software, and
> >> > then
> >> > enters the node and then pressed a button to add the node which is
> >> > supposed
> >> > to put in the PK's of the tables. So this is my code: (I posted this a
> >> > few
> >> > days ago, but am now getting an error)
> >> >
> >> > Private Sub cmdNode_Click()
> >> > Dim NodeID As Integer
> >> > Dim SoftwareID As Integer
> >> > NodeID = ID
> >> > SoftwareID = "SELECT Software.[ID] FROM Software where Software.[Name]
> >> > =
> >> > '"
> >> > + cmbSoftware.Value + " AND ServerID = '" + ServerID = "';"
> >> >
> >> > Dim sql As String
> >> >
> >> > sql = "INSERT INTO Node_Software([NodeID], [SoftwareID]) VALUES ("" &
> >> > NodeID & "", "" & SoftwareID & "")"
> >> >
> >> > MsgBox ("You have added a node")
> >> > DoCmd.RunSQL sql
> >> >
> >> > End Sub
> >> >
> >> > I keep getting an error message that MS Access can't append all the
> >> > records
> >> > in the appened query.. set 1 field(s) to Null due to conversion failure
> >> >
> >> > anyone have any idea what I did wrong?
> >> >
> >> >
> >> >
> >>
> >>
> >>
>
>
>
Re: insert into
"Ken Snell \(MVP\)" <kthsneisllis9[ at ]ncoomcastt.renaetl> 11/14/2008 7:07:06 PM
OK, I see the problem. You cannot set the SoftwareID variable to a SQL
statement string when the SoftwareID variable is Dim'd as an Integer.

I assume that you want to read the value of the SoftwareID field from the
Software table and use that value as the value of the SoftwareID variable;
is that correct? If yes, replace this line of code

SoftwareID = "SELECT Software.[ID] FROM Software where Software.[Name] = '"
+ cmbSoftware.Value + " AND ServerID = '" + ServerID = "';"


with these lines of code:

SoftwareID = DLookup("ID", "Software", "[Name] = '" & _
cmbSoftware.Value & "' AND [ServerID] = '" & _
ServerID & "'")

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


"short" <short[ at ]discussions.microsoft.com> wrote in message
news:67EB4A83-A17B-4A4D-9D27-D394330AFEF5[ at ]microsoft.com...
[Quoted Text]
> Both fields in the Node_software table are number fields. When I run the
> query and look in the Node_software table, I get the nodeId number but no
> softwareID
>
> "Ken Snell (MVP)" wrote:
>
>> A text field is one where the Data Type property of the field in the
>> table
>> is Text or Memo. A Text field can contain numeric values, but they are
>> not
>> numbers, they are characters that look like numbers.
>>
>> I see that I misread your original post. SoftwareID is dim'd as an
>> Integer,
>> not a Text -- my mistake.
>>
>> Are you sure that ID field is not NULL when your code runs?
>>
>> What are the Data Type properties of the two fields in the Node_Software
>> table?
>>
>> Also, the error message suggests that it did add the new record, but that
>> one field was given a NULL value. Which field is being assigned NULL by
>> the
>> query when it runs and gives you the error? Look at the table after you
>> run
>> the query and see.
>>
>> --
>>
>> Ken Snell
>> <MS ACCESS MVP>
>> http://www.accessmvp.com/KDSnell/
>>
>>
>> "short" <short[ at ]discussions.microsoft.com> wrote in message
>> news:1BD37B2B-55AB-478E-830F-1F2B94C330A4[ at ]microsoft.com...
>> > by text field does that include numbers?
>> >
>> > "Ken Snell (MVP)" wrote:
>> >
>> >> SoftwareID is a string variable, which is being put into the
>> >> SoftwareID
>> >> field, so I assume that the SoftwareID field is a text field.
>> >> Therefore,
>> >> you
>> >> must delimit the string text with " characters so that the insert
>> >> query
>> >> will
>> >> recognize the data as text:
>> >>
>> >> sql = "INSERT INTO Node_Software([NodeID], [SoftwareID]) VALUES ("" &
>> >> NodeID & "", """" & SoftwareID & """")"
>> >>
>> >> --
>> >>
>> >> Ken Snell
>> >> <MS ACCESS MVP>
>> >> http://www.accessmvp.com/KDSnell/
>> >>
>> >>
>> >>
>> >> "short" <short[ at ]discussions.microsoft.com> wrote in message
>> >> news:010662AD-37A3-4914-AA0D-684EE1DC6BDA[ at ]microsoft.com...
>> >> >I have a database that the users want to have a seperate table that
>> >> >holds
>> >> >the
>> >> > primary keys of two other tables. So I create a table with both
>> >> > tables
>> >> > primary keys in it:
>> >> > Software_Node
>> >> > NodeID
>> >> > SoftwareID
>> >> > (made both pk both numbers)
>> >> > which is connected to the Software and Node tables by their pk's.
>> >> >
>> >> > Now on the node form I have it where the user selects the software,
>> >> > and
>> >> > then
>> >> > enters the node and then pressed a button to add the node which is
>> >> > supposed
>> >> > to put in the PK's of the tables. So this is my code: (I posted this
>> >> > a
>> >> > few
>> >> > days ago, but am now getting an error)
>> >> >
>> >> > Private Sub cmdNode_Click()
>> >> > Dim NodeID As Integer
>> >> > Dim SoftwareID As Integer
>> >> > NodeID = ID
>> >> > SoftwareID = "SELECT Software.[ID] FROM Software where
>> >> > Software.[Name]
>> >> > =
>> >> > '"
>> >> > + cmbSoftware.Value + " AND ServerID = '" + ServerID = "';"
>> >> >
>> >> > Dim sql As String
>> >> >
>> >> > sql = "INSERT INTO Node_Software([NodeID], [SoftwareID]) VALUES (""
>> >> > &
>> >> > NodeID & "", "" & SoftwareID & "")"
>> >> >
>> >> > MsgBox ("You have added a node")
>> >> > DoCmd.RunSQL sql
>> >> >
>> >> > End Sub
>> >> >
>> >> > I keep getting an error message that MS Access can't append all the
>> >> > records
>> >> > in the appened query.. set 1 field(s) to Null due to conversion
>> >> > failure
>> >> >
>> >> > anyone have any idea what I did wrong?
>> >> >
>> >> >
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>


Re: insert into
short 11/14/2008 8:25:00 PM
Last question, I have a severId that I'm storing as well do I need to use the
DLookup for that as well?

ServerID = "SELECT Server.[ID] FROM Server where Server.[Name] = '" +
cmbServer.Value + "';"

Thank you very much for you help!


"Ken Snell (MVP)" wrote:

[Quoted Text]
> OK, I see the problem. You cannot set the SoftwareID variable to a SQL
> statement string when the SoftwareID variable is Dim'd as an Integer.
>
> I assume that you want to read the value of the SoftwareID field from the
> Software table and use that value as the value of the SoftwareID variable;
> is that correct? If yes, replace this line of code
>
> SoftwareID = "SELECT Software.[ID] FROM Software where Software.[Name] = '"
> + cmbSoftware.Value + " AND ServerID = '" + ServerID = "';"
>
>
> with these lines of code:
>
> SoftwareID = DLookup("ID", "Software", "[Name] = '" & _
> cmbSoftware.Value & "' AND [ServerID] = '" & _
> ServerID & "'")
>
> --
>
> Ken Snell
> <MS ACCESS MVP>
> http://www.accessmvp.com/KDSnell/
>
>
> "short" <short[ at ]discussions.microsoft.com> wrote in message
> news:67EB4A83-A17B-4A4D-9D27-D394330AFEF5[ at ]microsoft.com...
> > Both fields in the Node_software table are number fields. When I run the
> > query and look in the Node_software table, I get the nodeId number but no
> > softwareID
> >
> > "Ken Snell (MVP)" wrote:
> >
> >> A text field is one where the Data Type property of the field in the
> >> table
> >> is Text or Memo. A Text field can contain numeric values, but they are
> >> not
> >> numbers, they are characters that look like numbers.
> >>
> >> I see that I misread your original post. SoftwareID is dim'd as an
> >> Integer,
> >> not a Text -- my mistake.
> >>
> >> Are you sure that ID field is not NULL when your code runs?
> >>
> >> What are the Data Type properties of the two fields in the Node_Software
> >> table?
> >>
> >> Also, the error message suggests that it did add the new record, but that
> >> one field was given a NULL value. Which field is being assigned NULL by
> >> the
> >> query when it runs and gives you the error? Look at the table after you
> >> run
> >> the query and see.
> >>
> >> --
> >>
> >> Ken Snell
> >> <MS ACCESS MVP>
> >> http://www.accessmvp.com/KDSnell/
> >>
> >>
> >> "short" <short[ at ]discussions.microsoft.com> wrote in message
> >> news:1BD37B2B-55AB-478E-830F-1F2B94C330A4[ at ]microsoft.com...
> >> > by text field does that include numbers?
> >> >
> >> > "Ken Snell (MVP)" wrote:
> >> >
> >> >> SoftwareID is a string variable, which is being put into the
> >> >> SoftwareID
> >> >> field, so I assume that the SoftwareID field is a text field.
> >> >> Therefore,
> >> >> you
> >> >> must delimit the string text with " characters so that the insert
> >> >> query
> >> >> will
> >> >> recognize the data as text:
> >> >>
> >> >> sql = "INSERT INTO Node_Software([NodeID], [SoftwareID]) VALUES ("" &
> >> >> NodeID & "", """" & SoftwareID & """")"
> >> >>
> >> >> --
> >> >>
> >> >> Ken Snell
> >> >> <MS ACCESS MVP>
> >> >> http://www.accessmvp.com/KDSnell/
> >> >>
> >> >>
> >> >>
> >> >> "short" <short[ at ]discussions.microsoft.com> wrote in message
> >> >> news:010662AD-37A3-4914-AA0D-684EE1DC6BDA[ at ]microsoft.com...
> >> >> >I have a database that the users want to have a seperate table that
> >> >> >holds
> >> >> >the
> >> >> > primary keys of two other tables. So I create a table with both
> >> >> > tables
> >> >> > primary keys in it:
> >> >> > Software_Node
> >> >> > NodeID
> >> >> > SoftwareID
> >> >> > (made both pk both numbers)
> >> >> > which is connected to the Software and Node tables by their pk's.
> >> >> >
> >> >> > Now on the node form I have it where the user selects the software,
> >> >> > and
> >> >> > then
> >> >> > enters the node and then pressed a button to add the node which is
> >> >> > supposed
> >> >> > to put in the PK's of the tables. So this is my code: (I posted this
> >> >> > a
> >> >> > few
> >> >> > days ago, but am now getting an error)
> >> >> >
> >> >> > Private Sub cmdNode_Click()
> >> >> > Dim NodeID As Integer
> >> >> > Dim SoftwareID As Integer
> >> >> > NodeID = ID
> >> >> > SoftwareID = "SELECT Software.[ID] FROM Software where
> >> >> > Software.[Name]
> >> >> > =
> >> >> > '"
> >> >> > + cmbSoftware.Value + " AND ServerID = '" + ServerID = "';"
> >> >> >
> >> >> > Dim sql As String
> >> >> >
> >> >> > sql = "INSERT INTO Node_Software([NodeID], [SoftwareID]) VALUES (""
> >> >> > &
> >> >> > NodeID & "", "" & SoftwareID & "")"
> >> >> >
> >> >> > MsgBox ("You have added a node")
> >> >> > DoCmd.RunSQL sql
> >> >> >
> >> >> > End Sub
> >> >> >
> >> >> > I keep getting an error message that MS Access can't append all the
> >> >> > records
> >> >> > in the appened query.. set 1 field(s) to Null due to conversion
> >> >> > failure
> >> >> >
> >> >> > anyone have any idea what I did wrong?
> >> >> >
> >> >> >
> >> >> >
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
Re: insert into
"Ken Snell \(MVP\)" <kthsneisllis9[ at ]ncoomcastt.renaetl> 11/15/2008 4:47:43 AM
Yes.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


"short" <short[ at ]discussions.microsoft.com> wrote in message
news:4EBB49B6-19BA-49D9-82B5-C9629DEB7811[ at ]microsoft.com...
[Quoted Text]
> Last question, I have a severId that I'm storing as well do I need to use
> the
> DLookup for that as well?
>
> ServerID = "SELECT Server.[ID] FROM Server where Server.[Name] = '" +
> cmbServer.Value + "';"
>
> Thank you very much for you help!


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net