Access VBA - Open Form to Specific Record from Report

感情迁移 提交于 2021-02-10 07:47:04

问题


I have a report that lists Deposits, with the DepositID set as a hyperlink. OnClick of DepositID, it opens the Deposit Entry form to that particular record. However, the form opens to a new record instead of the one the user clicks on. I think it is because I have another bit of code that runs OnLoad of the form that goes to a new record, and it might be executing that after executing the OnClick code.

OnClick of DepositID from the report:

DoCmd.OpenForm "DepositForm", acNormal, "", "[DepositID]= " & [DepositID]

OnLoad of the Form:

DoCmd.GoToRecord , , acNewRec

Is the OnLoad code running after the OnClick code, and effectively not showing the specified record from the report? Not sure how to fix.


回答1:


I wouldn't be using the AddNewRecord in your OnLoad event.

If you're using the form for both edit/add purposes, you should have two command buttons that open the form - one for each purpose

Remove this line from Form_Load

DoCmd.GoToRecord , , acNewRec

Use the edit command you have right now exactly as is - or add EditMode

DoCmd.OpenForm "DepositForm", acNormal, "", "[DepositID]= " & [DepositID], acFormEdit

Add a new button to Add New Records as in:

DoCmd.OpenForm "DepositForm", acNormal, , , acFormAdd


来源:https://stackoverflow.com/questions/38729591/access-vba-open-form-to-specific-record-from-report

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!