抱歉,大家的文字墙很长,但这需要解释,要发布的代码太多了......
我正在将固定宽度文件导入到需要数据输入的方法中。我使用transferText 将文件导入到两个规范中(一个是全局的,另一个是特殊情况)。
我有一个函数,它使用 DAO 循环遍历 TableDefs 中的所有 Field 对象,以构建包含 AutoIncrement PK 的重复表,以便我能够编辑这些记录。我使用 INSERT INTO 将数据推送到该表中。
效果很好。发现错误后,用户进入数据输入以手动更正它们,这比筛选 400 个字符行并按应有的方式重新组织所有内容要好。效果很好!
问题:当数据输入发生更改时,按下提交按钮,该按钮调用表单外部模块内的函数。它关闭数据输入表单,并将信息推回到原始表减去自动增量的 PK,并且应该删除带有 ID 的复制表,并生成一个新表,再次搜索错误...
它可以很好地推回原始状态,但不会删除 ID 表。总是返回给我一条消息,指示该表已锁定。我注意到该表被无限期锁定,直到所有函数/子程序退出。在任何时候单步执行代码我都无法手动删除它,一旦执行完成我就可以将其删除。
我假设由于我通过表单中的命令调用了它,因此在所有代码完成并且可以调用表单终止并执行其操作之前,锁不会被释放。有什么想法吗?是的,这非常野蛮,但效果很好,我只需要能够将另一张桌子从地球上撕下来,这样我就可以重新放置更新的副本......
在最坏的情况下,我可以让用户关闭表单并点击主表单中的另一个按钮,但这是在设计时充分考虑到用户能力的。然而,这现在引起了我的全部关注,并且希望至少找到一种解决方案,即使它不是最佳方案。
-EDIT-
该问题使用了两种形式
FormA (Role: Load in and search for problems)
Examine button is pressed that:
- Uses TextTransfer based on predefined specs into tempExtract to
import the file
- DAO fires off on the Fields collection in tableDefs for
tempExtract, creates new table tempExtractID
- Performs searches through the file to find errors. Errors are saved to
a table Problem_t. Table contains Problem_ID (Set from the ID field
added to tempExtractID) and Description
- Execution of these tasks is successfully requerying the initial
form to showing a list of problems and number of occurances. A button
gains visibility, with onClick that opens the form DataEntry.
- At this point in the code after DAO execution, I can DROP the table
tempExtractID. DAO is NOT used again and was only used to build a new table.
FormB - 数据输入表
一旦我打开此表单,表 tempExtractID 就会被锁定,并且我无法删除该表。表单的记录源根据 Problems_t 中的 ID 查询 tempExtractID,以仅返回我们需要键入的内容。
在表单完全终止之前我无法删除该表。按下数据输入表单上的按钮即可提交更改,其中只有5在出现锁定错误之前触发的代码行。
*Xargs refers to the list of Field names pulled earlier through DAO. As DAO loops through Field objects, the physical names are added to an Xargs String which is placed in this table. Basically everything but the AutoNumber is being inserted back
docmd.Close acForm, "frmDataEntry", acSaveNo
call reInitializeExtract
> docmd.RunSQL "DELETE FROM tempExtract"
> docmd.RunSQL "INSERT INTO tempExtract SELECT (" & DLookup("Value", "CONFIG_t", "Item = 'Xargs'" & ") FROM tempExtractID"
docmd.DeleteObject acTable, "tempExtractID"
这是在打开表单(表首次被锁定时)之间运行的唯一代码,并继续锁定直到所有子函数和函数完成。