bind checkbox with a bit column in a SQL Server linked table

a 夏天 提交于 2019-12-23 21:39:05

问题


I'm trying to bind a checkbox with a bit column in a SQL Server linked table.

I had an error about the type at first, then I went in my linked table in access and changed the display control of the column to checkbox instead of textbox.

Now I have a write conflict error when I save the record.

I tried the solution about adding a timestamps in the table but I got the same problem

Is it possible without VBA?

Thank you

The code of my save button

Private Sub btnSave_Click()
  On Error GoTo Err_btnSave_Click
      DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
      DoCmd.Close
  Exit_btnSave_Click:
      Exit Sub

  Err_btnSave_Click:
      MsgBox Err.Description
      Resume Exit_btnSave_Click

End Sub

I don't think there's anything wrong there. I got the error only when there's a checkbox bound to a bit column

I tried to bound a textbox to the same column. The value is false by default and I don't have the error if I don't change is value.

but when the form is dirty, even if I change the value of an another control, I got the error.

I don't understand. It's like if Access doesn't understand that there's only one user when there's a control bound to a bit column.

The last time I had this problem, I gave up and I change the type for a small int but I'm curious. Is there a way to make it worth with a Bit. all I want is a Boolean.


回答1:


Check if the bit field in SQL server is nullable. If it is, make it non-null and set the default value in SQL server to 0 (false). There is a discussion of this issue with nullable bit fields here: Nullable bool fields in MS Access linked tables




回答2:


I had an error about the type at first...

This is your first clue. Go back to SQL Server and make certain that your bit is actually a bit. Assuming you have to change the data type in your database, you will need to either relink to the table or delete the table and link again.

If you cannot change the data type of the column in SQL Server, then you may need to use VBA. MS Access 2010 might have a wizard on configuring a checkbox to a text data type field. However, if the database ever stores a value other than the 2 (hopefully not more) that you configured, Bad Things will likely happen.

I went in my linked table in access and changed the display control of the column to checkbox instead of textbox...

This has no bearing on read/write. It simply determines the default control when creating forms with that column.




回答3:


Bit field when linked to Access , you can not have NULL values. So we need to make sure that bit field has a default value of either 0 or 1 so when new record is added to table, it will have default value and not NULL. This is because the ODBC driver do not know NULL values for bit fields.



来源:https://stackoverflow.com/questions/13841539/bind-checkbox-with-a-bit-column-in-a-sql-server-linked-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!