How to insert zero in an integer field with VBA?

I have ADP Access Access with SQL Server. I want to take a bunch of values ​​from a form and paste them into a table. Some of the values ​​may be empty. How to use vba to insert zero into integer field in SQL Server table?

I tried

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

and

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

None worked.

+3
source share
3 answers

If the field will be null, then just leave it outside the list of fields and it will get a null value. Therefore, given the table with the name, address, telephone, making the equivalent

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

will leave a phone number with a zero value

+4
source

your second example looks good

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

me.myInt - , . myInt , .

+3

what error occurs when you run your code?

They say that we have a table ... [test] with the columns [id], [test] and [test 2].

you could write;

insert into [test] ([test], [test 2]) values ( null, null)

make sure your line where you pass the command is at zero without any decorations ... there are no single or double quotes.

+1
source

Source: https://habr.com/ru/post/1772894/


All Articles