如何索取表格的最后一条记录的ID? [英] How to get the last record id of a form?

查看:262
本文介绍了如何索取表格的最后一条记录的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在接入的形式。

I currently have a form in access.

我想要做的就是添加的最后一个记录的值。

What I want to do is get the value of the last record added.

例如,如果我有10条记录,我想要得到的值10,因为这是最后添加记录的ID。我想运行的功能最后一个ID插入()查询,但它不能正常工作。

For example, if i have 10 records, I want to get the value "10", because this is the id of the added last record. I am trying to run a query with the function last id inserted() but it is not working.

这在code我使用的:

This the code I am using :

Dim lastID As Integer
Query = "select last_insert_id()"
lastID = Query
MsgBox (lastID)

我在想什么?

What am I missing?

推荐答案

有一个函数 DMAX 将抓取的最高数量。

There is a function DMax that will grab the highest number.

Dim lastID As Integer
lastID = DMax("IDField","YourTable")
' or = DMax("IDField","YourTable","WhenField=Value")
MsgBox lastID

其他的域功能的是:

  • DAVG
  • DCOUNT
  • DFirst
  • DLast
  • 使用DLookup
  • DMIN
  • DSTDEV
  • DSTDEVP
  • 使用DSum
  • 女工
  • DVARP
  • DAvg
  • DCount
  • DFirst
  • DLast
  • DLookup
  • DMin
  • DStDev
  • DStDevP
  • DSum
  • DVar
  • DVarP

请与你的友好<大骨节病> F1 键以获得更多信息。

Check with your friendly F1 key for more info

这篇关于如何索取表格的最后一条记录的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆