在使用SQL后端时,以形式维护自动化功能
目前,我正在尝试从访问后端转移到我的数据库的SQL后端,同时仍将访问表作为前端。这是通过与我的后端连接的链接表来完成的。该表格旨在将新记录添加到表中。问题在于自动化量。 ID设置为自动数,表单将在等待用户添加剩余列的同时显示(新)。我已经使用Identity属性设置了SQL数据,因此创建了新记录后,它将增加。但是,我无法获得与以前相同的表单,因为即使后端会自动添加下一个顺序ID,我也无法在用户实际保存表单数据之前自动填充该数据。是否有一种方法维护自动化器提供的形式功能?
TL; DR:表格在更改为数字后无法正常工作。
Currently, I am trying to move from an Access backend to a SQL backend for my database while still keeping the Access form as the frontend. This is done via linked tables with ODBC connections to my backend. The form is designed to add new records to the table. The problem is with AutoNumber. The ID was set as an AutoNumber and the form would simply display (New) while waiting for the user to add the remaining columns. I have set up my SQL data with the IDENTITY property, so it will increment once a new record is created. However, I cannot get the form to behave the same way as it did because, even though the backend will automatically add the next sequential ID, I cannot automatically fill that data into the form prior to a user actually saving the form data. Is there a way maintain the form functionality that AutoNumber provides?
TL;DR: Form is not working correctly after AutoNumber is changed to Number.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,在保存记录之前,有一些“罕见”案例实际上需要Autonumberr。例如,如果您有子形式,则访问始终可以自动保存主记录,因此自动化器是和将创建的。并没有代码。
现在,在某些情况下,您需要自动化器。假设您有一些“代码”需要运行并吐出一些子记录。
一般方法是简单地执行当时的记录保存。
因此,假设有一个按钮或某些代码需要以表格运行,并且您需要PK自动化器吗?
您可以使用此代码:
上述工作记录必须是“肮脏”的,但是在所有情况下,情况往往是这种情况。 “罕见”的例外表明您可以检查我。ISNEWRECORD,但是在大多数情况下,上述代码就足够了。
我真的无法想象某些自动数的“显示”在用户开始输入数据时非常重要。
但是,如果您希望自动化器在任何按键后出现(表格上的数据输入)?
只需将此代码行放入后的插入事件中:
因此,现在,当查看表单时,用户在任何文本框中的第一个键按键将迫使自动数生成并出现。但是,将自动数ID的任何含义分配给最终用户是一种非常糟糕的做法。实际上,在大多数情况下应该隐藏ID。
上面的唯一问题或缺点当然是,如果您有任何必需的列,则以上可能会出错或出现问题。
Well, there are "rare" cases in which you actually need the autonumberr before you save the record. For example, if you have a sub-form, then Access ALWAYS does a automatic save of the main record, and thus the autonumber is and will have been created .So a main form, and sub form (child table) will work fine, and do so without code.
Now, there are some cases in which you need the autonumber. Say you have some "code" that needs to run and spit out some child records.
The general approach is to simply execute a record save at that point in time.
So, say there is a button, or some code you need to run in the form, and you NEED the PK autonumber?
You can use this code:
the record for above to work will have to be "dirty", but in near all cases, this tends to be the case. The "rare" exceptions would suggest that you could check me.IsNewRecord, but in most cases the above bit of code will suffice.
I can't really imagine that the "display" of some autonumber is oh so important WHEN the user is starting to enter data.
However, if you want the autonumber to appear after ANY keypress (data entry on the form)?
Simply put this line of code in the after insert event:
So, now when looking at a form, the FIRST key press by the user in any text box will force the autonumber to be generated and appear. However, it is a VERY bad practice to assign any meaning of the autonumber ID to the end users. In fact that ID should in most cases be hidden.
the only issue or downside of above is of course that if you have any required columns, then the above may error out or case an issue.
解决方案
对于此问题,我需要将我的Identity_insert设置为SQL后端。这是要这样做的代码:
另外,如果收到错误:
table< table name>没有身份属性。
使用具有身份的自动插图列重新创建表。示例:
有关Microsoft ofical文档中身份的更多信息:在这里
Solution
For this problem, I needed to set my identity_insert to ON in the SQL backend. Here is the code to do so:
Also, if you get the error:
Table <Table Name> does not have the identity property.
recreate the table with the autoincrementing column having an identity.Example:
More on IDENTITY in Microsoft offical documentation: here