0

好的,这是交易。我有一个以前存在的 SQL Server 2008 数据库,它通过链接表/视图链接到 Access 2002 数据库。到目前为止,项目代码一直是一个nvarchar类型。

我有一个将项目代码转换为的 SQL 查询Int和一个使用该MAX()函数为我提供最高值的 Access 2002 链接查询。每次选择“新建”记录按钮时,我希望从这个最高值开始将项目代码增加 1。

Right now, when "New" is selected, the form is blank, waiting for input. What I want to do is, when "New" is selected, to have the value of the MAX()function query passed to a variable, have 1 added to it, and the resulting value placed in the "Item Code" text box.

这听起来很容易,但由于某种原因,我似乎无法让它工作。我非常了解 Access,但我的 VBA 相当薄弱。

4

2 回答 2

0

听起来可以通过自定义功能完成。

Dim rs as dao.recordset
Dim db as dao.database
Dim NextInt as string

set db = currentDb
set rs = db.openrecordset(YourMaxQuery,dbOpenSnapshot,dbSeeChanges)

if rs.recordCount >0 THEN
   NextInt = Cstr(rs!MaxValue + 1)
END

set rs = nothing
set db = nothing

return NextInt

在查询的更新语句中调用该函数,它应该为您提供您正在寻找的值。

于 2015-06-29T13:42:59.423 回答
0

对不起,我花了这么长时间才回到这个线程。

好的,我最终在 MS SQL Server 2008 中使用了 GlobalSequence。基本上只是创建了一个最大 id 值作为种子的表,并将它与一个具有位值的列匹配,以防止回滚和重复的项目代码应该记录被删除。在那之后,这很容易。:)

于 2015-07-07T19:21:14.623 回答