A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

insert into



 
 
Thread Tools Display Modes
  #1  
Old May 18th, 2010, 10:05 PM posted to microsoft.public.access.queries
seeker
external usenet poster
 
Posts: 133
Default insert into

I have an insert into query which is as follows;

strgoaldescription = InputBox("Type new goal.")
strservicetype = InputBox("This goal is for what service?")
intprGroup = InputBox("Indicate the pr_group number if any")
intprGroup = IIf(intprGroup = "", Null, intprGroup)
strsql = "insert into goal (goal_description,los_id,pr_group_id) values('"
& strgoaldescription & "', '" & strservicetype & "', " & IIf(intprGroup = "",
Null, intprGroup) & ")"

the query throws an error when intprgroup is null. There will be times when
this is the case so how do I pass null to the field via an insert into query.
the field allows nulls to be in it.
  #2  
Old May 19th, 2010, 02:28 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default insert into

Try something like the following.

strsql = "insert into goal (goal_description,los_id,pr_group_id) " & _
"values('" & strgoaldescription & "', '" & strservicetype & "', " & _
IIf(intprGroup & "" = "", " NULL", " '" & intprGroup & "' ") & ")"



John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

seeker wrote:
I have an insert into query which is as follows;

strgoaldescription = InputBox("Type new goal.")
strservicetype = InputBox("This goal is for what service?")
intprGroup = InputBox("Indicate the pr_group number if any")
intprGroup = IIf(intprGroup = "", Null, intprGroup)
strsql = "insert into goal (goal_description,los_id,pr_group_id) values('"
& strgoaldescription & "', '" & strservicetype & "', " & IIf(intprGroup = "",
Null, intprGroup) & ")"

the query throws an error when intprgroup is null. There will be times when
this is the case so how do I pass null to the field via an insert into query.
the field allows nulls to be in it.

  #3  
Old May 19th, 2010, 03:46 PM posted to microsoft.public.access.queries
seeker
external usenet poster
 
Posts: 133
Default insert into

That seemed to work. Don't know why but it seems to work. Thanks.

"John Spencer" wrote:

Try something like the following.

strsql = "insert into goal (goal_description,los_id,pr_group_id) " & _
"values('" & strgoaldescription & "', '" & strservicetype & "', " & _
IIf(intprGroup & "" = "", " NULL", " '" & intprGroup & "' ") & ")"



John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

seeker wrote:
I have an insert into query which is as follows;

strgoaldescription = InputBox("Type new goal.")
strservicetype = InputBox("This goal is for what service?")
intprGroup = InputBox("Indicate the pr_group number if any")
intprGroup = IIf(intprGroup = "", Null, intprGroup)
strsql = "insert into goal (goal_description,los_id,pr_group_id) values('"
& strgoaldescription & "', '" & strservicetype & "', " & IIf(intprGroup = "",
Null, intprGroup) & ")"

the query throws an error when intprgroup is null. There will be times when
this is the case so how do I pass null to the field via an insert into query.
the field allows nulls to be in it.

.

  #4  
Old May 19th, 2010, 09:04 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default insert into

Try using
Debug.Print strSQL
to examine the created string.



John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

seeker wrote:
That seemed to work. Don't know why but it seems to work. Thanks.

"John Spencer" wrote:

Try something like the following.

strsql = "insert into goal (goal_description,los_id,pr_group_id) " & _
"values('" & strgoaldescription & "', '" & strservicetype & "', " & _
IIf(intprGroup & "" = "", " NULL", " '" & intprGroup & "' ") & ")"



John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

seeker wrote:
I have an insert into query which is as follows;

strgoaldescription = InputBox("Type new goal.")
strservicetype = InputBox("This goal is for what service?")
intprGroup = InputBox("Indicate the pr_group number if any")
intprGroup = IIf(intprGroup = "", Null, intprGroup)
strsql = "insert into goal (goal_description,los_id,pr_group_id) values('"
& strgoaldescription & "', '" & strservicetype & "', " & IIf(intprGroup = "",
Null, intprGroup) & ")"

the query throws an error when intprgroup is null. There will be times when
this is the case so how do I pass null to the field via an insert into query.
the field allows nulls to be in it.

.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:46 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.