[AccessD] Insert Into with Null Fields

Susan Harkins ssharkins at gmail.com
Sun Nov 11 18:18:08 CST 2007


INSERT INTO doesn't care if a value doesn't exist, it only cares about the 
placeholder. When txtA is empty, insert a zero-length string.

If IsNull(txtA) then txtA = ''

Stg = "INSERT INTO tblMain ( A, B, C )" _
& " VALUES ('" & txtA & "', '" & txtB & "', '" & txtC & "')"

Susan H.

----- Original Message ----- 
From: "Dan Waters" <dwaters at usinternet.com>
To: "'Access Developers discussion and problem solving'" 
<accessd at databaseadvisors.com>
Sent: Sunday, November 11, 2007 3:10 PM
Subject: Re: [AccessD] Insert Into with Null Fields


> Hi Susan,
>
> If IsNull(txtA) then
> Stg = "INSERT INTO tblMain ( B, C )" _
> & " VALUES ('" & txtB & "', '" & txtC & "')"
> Else
> Stg = "INSERT INTO tblMain ( A, B, C )" _
> & " VALUES ('" & txtA & "', '" & txtB & "', '" & txtC & "')"
> End If
>
> Trying to insert a Null value creates an error.
>
> Dan
>
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Susan Harkins
> Sent: Sunday, November 11, 2007 1:49 PM
> To: Access Developers discussion and problem solving
> Subject: Re: [AccessD] Insert Into with Null Fields
>
>
>
>> Sometimes when I write an INSERT INTO string, I have to take into account
>> that a text box or memo field might be null.  If there is one possibility
>> of
>> a Null, I have to write and choose from 2 different strings, if there are
>> two possibilities of Null fields, then I have to write and choose from 4
>> different strings, and so on.
>>
>> Is there a way out of this?
>
> =========I don't understand the need for mutliple statements. Can you
> provide a simple example?
>
> Susan H.
>
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com 




More information about the AccessD mailing list