sql - combobox.column property returns invalid use of null in vba -
i database//access noob, bear me. have database set keep track of consultants , vendors tech consulting company. consultants own vendors, , have third-party vendors handle contracting. in case consultant own vendor, contact information same both. contact info stored in separate table, primary key contactid , foreign key fields consultantid (primary key in consultantt) , vendorid (primary key in vendort).
in case relevant contact info has been entered on 1 of forms, want able select existing contact info record , tell database add other foreign key id field existing record based on record on main form. so, example, if have entered contact info consultant via consultant form, when open vendor form add consultant a's vendor want option select "consultant a" combo box , have info populate vendorsf's contact info form while adding vendorid existing contact info record consultant a.
i think i've worked out, stuck on 1 last thing. right have popup form (chooseconsultantinfof) selecting existing contactinfo record. on form have search combobox (selectconsultantcombo) select existing record, , command button (saveconsultantbtn) i've tried code update contactinfot , add vendorid current record on vendorsf existing record in contactinfot. here of code popup form:
option compare database option explicit private sub saveconsultantbtn_click() dim stupid long stupid = selectconsultantcombo.column(0) docmd.runsql "update contactinfot set vendorid = (forms!vendorsf!vendorid) contactinfoid = " & stupid & ";" end sub private sub selectconsultantcombo_afterupdate() dim rst dao.recordset set rst = me.recordsetclone rst.findfirst "contactinfoid = " & me!selectconsultantcombo me.bookmark = rst.bookmark leave: me!selectconsultantcombo = null if not rst nothing set rst = nothing exit sub end sub
when try put action, error 94: invalid use of null , pulls up
stupid = selectconsultantcombo.column(0)
i know code block works apart that--i tried click event once numeric value instead of variable:
private sub saveconsultantbtn_click() docmd.runsql "update contactinfot set vendorid = (forms!vendorsf!vendorid) contactinfoid = 1 ;" end sub
without trouble, issue must in calling combobox's column.
i tried defining variable nz allow null:
stupid = nz(me.selectconsultantcombo.column(0), 0)
and gets code working also, still doesn't save vendorid record in contactinfot. none of columns in combobox contain null values (none can find, anyway). dunno if useful, row source of combobox is:
select contactinfot.contactinfoid, consultantt.consultantid, consultantt.firstname, consultantt.lastname consultantt inner join contactinfot on consultantt.consultantid = contactinfot.consultantid order consultantt.[lastname], consultantt.[firstname];
does know why access doesn't recognize combobox.column property? or there way write in vba avoid error?
first try stupid = me.selectconsultantcombo.column(0)
(you missing me.
part).
but should make sure bound column on combo box set correctly , use stupid = me.selectconsultantcombo