insert into

S

seeker

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.
 
J

John Spencer

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
 
J

John Spencer

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
 

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

Top