尝试从表'发票'中的最近记录获取RecieptNumber(autonumber)以将值存储在变量invoiceNum(integer)中。访问(VBA)访问记录集中的最后一条记录
Dim rstInvoices As Recordset
Set cdCurrentDatabase = CurrentDb
Set rstInvoices = cdCurrentDatabase.OpenRecordset("SELECT LAST ([RecieptNumber]) FROM Invoices;")
invoiceNum = rstInvoices("[RecieptNumber]").Value
昨天开始VBA编程,非常感谢任何帮助,我将能够理解。
您的要求:'SELECT LAST([RecieptNumber])如rNum FROM Invoices'您的vba:'InvoicesinvoiceNum = rstInvoices.Fields(“rNum”)。Value'。另请参阅:http://msdn.microsoft.com/fr-fr/library/office/ff197799(v=office.15).aspx – scraaappy 2014-12-10 22:57:49
[如何获取表单的最后一条记录ID?]( http://stackoverflow.com/questions/13587638/how-to-get-the-last-record-id-of-a-form) – LondonRob 2014-12-10 23:02:28
如果你在一个多用户系统上,任何涉及Last,Top等的东西,是非常危险的,你需要一个CurrentDb和@@ Identity的实例,参见http://stackoverflow.com/questions/1628267/autonumber-value-of-last-inserted-row-ms-access-vba – Fionnuala 2014-12-11 01:28:33