vba - MS Access 2013 saved append query not updating all fields -


i have saved query, qryinsertlog follows:

parameters useridpar long, unitidpar long, logentrypar longtext, fnotespar longtext; insert tbllogbook ( userid, unitid, logentry, fnotes ) select [useridpar] expr1, [unitidpar] expr2, [logentrypar] expr3, [fnotespar] expr4; 

i'm trying run query when save button clicked on unbound form, parameters gathered form controls. vba code save button is:

private sub cmdsave_click()  dim db dao.database dim qdf dao.querydef dim oktosave boolean  if me.cbouser.value = 0 or isnull(me.cbouser.value)     msgbox "you must choose user. record not saved."     oktosave = false elseif me.cbounit.value = 0 or isnull(me.cbounit.value)     msgbox "you must choose unit. record not saved."     oktosave = false elseif me.txtlogentry.value = "" or isnull(me.txtlogentry.value)    msgbox "you must have somtehing log. record not saved."     oktosave = false else     oktosave = true end if  set db = currentdb set qdf = db.querydefs("qryinsertlog")  qdf.parameters("useridpar").value = me.cbouser.value qdf.parameters("unitidpar").value = me.cbounit.value qdf.parameters("logentrypar").value = me.txtlogentry.value qdf.parameters("fnotespar").value = iif(isnull(me.txtfnotes.value), "", me.txtfnotes.value)  if oktosave      qdf.execute end if  qdf.close set qdf = nothing  end sub 

when code run, fnotes field of table isn't updated. other 3 fields update expected. fnotes field isn't required. hardcoded string fnotes paramater so:

qdf.parameters("fnotespar").value = "why doesn't work" 

rather using form control value, , got same result: field doesn't update. when run query access objects window , supply parameter values prompts, works fine. when create form that's bound table, seems work fine.

i can't figure out why there's no trouble updating logentry field fnotes field fails update.

add new record via dao.recordset instead of dao.querydef.

first, include declaration ...

dim rs dao.recordset 

then use after set db = currentdb ....

set rs = db.openrecordset("tbllogbook") rs     if oktosave         .addnew         !userid = me.cbouser.value         !unitid = me.cbounit.value         !logentry = me.txtlogentry.value         !fnotes = nz(me.txtfnotes.value, "")         .update     end if     .close end 

note nz(me.txtfnotes.value, "") gives same thing iif(isnull(me.txtfnotes.value), "", me.txtfnotes.value), more concisely.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -