Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I insert null into an integer field with VBA?

I have an MS Access ADP with a SQL server backend. I want to take a bunch of values from a form and insert them into a table. Some of the values can be null. How do I use vba to insert null into an integer field in the SQL Server table?

I tried

"insert...values(" & nz(me.myInt, null) & ",..."

and

"insert...values(" & nz(me.myInt, "null") & ",..."

Neither worked.

like image 579
dmr Avatar asked Dec 01 '25 17:12

dmr


2 Answers

IF the field will accept nulls then simply leave it out of the list of fields and it will get a null value. So given a table with Name, Address, phone, doing the equivalent of

INSERT table(Name, Address) VALUES('fred','Toytown')

will leave the phone number with a null value

like image 190
Kevin O'Donovan Avatar answered Dec 03 '25 09:12

Kevin O'Donovan


your second example looks good

("insert...values(" & nz(me.myInt, "null") & ",...")

but only if me.myInt is a variant, a control, or a field. If myInt is an integer or a long, then it cannot be null.

like image 25
phoog Avatar answered Dec 03 '25 10:12

phoog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!