access vba - Avoid Invalid use of Null error when the field is empty -


i created form in access 2010 , fill in form based on text boxes (b , c) , selection form combobox (a). problem if of text box left empty “invalid use of null” error. noticed can avoid error if dim text boxes variant instead of integer. not sure if right solution. can change following script avoid error?

private sub abcboxenter_click() dim string dim b integer dim c integer if not isnull(me!combobox.value)     = me!combobox.value     b = afield     c = bfield     values = "values ("     values = values & "'" & id & "','" & & "','" & b & "','" & c & "')"     sql = "insert  contacttable (id, a, b, c)"     sql = sql & values     docmd.runsql sql     me.b.value = ""     me.c.value = "" end if end sub 

you can use nz:

values = values & "'" & nz(id) & "','" & nz(a) & "','" & nz(b) & "','" & nz(c) & "')" 

or, better, implement function csql


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -