SQL Server Access组合框将空字符串替换为null,然后引发错误3162

hgb9j2n6  于 2022-12-10  发布在  其他
关注(0)|答案(1)|浏览(93)

I have an Access form bound to linked view called vwBudgetEntries from SQL Server. The form contains a combo box bound to a field called SubcodeID which is short text and has the following properties:

Meanwhile, the row source of the combo box pulls a unique list of all subcode id's, including one where it's an empty string. For some reason, however, selecting this option throws the following error:

For the life of me, I can't figure out why. The value should be empty string, not null. If I change the combo box to a textbox and enter "" , the update is accepted without any errors.
I've done what research I can and, so far, I've only found 2 workarounds:

  1. Change the field properties to allow null, then replace null values with an empty string after the control updates.
  2. Trap the error in the form_error event, undo the update and supply the value using VBA.
    Neither workaround is ideal. Can someone explain why this error is occurring in the first place and what I might do to fix it?
sulc1iza

sulc1iza1#

除了非常特殊的情况之外,应该避免存储空字符串,否则你会遇到类似这样的问题。

  • 将“必需”设置为“否”
  • 将“允许零长度”设置为“否”
  • SubcodeID的未知值选择存储 Null

相关问题