很简单,先取id后update。不过,要注意的是,这时cursor的位置要设为adUseServer。因为,如果设为adUseClient,那AddNew之后得到的ID值是NULL。
- Set rstNewDetail = New ADODB.Recordset
- With rstNewDetail
- .ActiveConnection = CurrentProject.Connection
- .Source = strDetailTable
- .CursorLocation = adUseServer
- .CursorType = adOpenDynamic
- .LockType = adLockOptimistic
- .Open Options:=adCmdTableDirect
- End With
- With rstNewDetail
- .AddNew
- lId = .Fields("lngId")
- .Update
- End With
参考文献:http://access911.net/fixhtm/71FABF1E17DC.htm?tt=