使用 vba 在 Access 2010 中使用不同表单中的 ID 打开表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17046407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open a form using ID from a different form in Access 2010 using vba
提问by KuroNeko
I am trying to open a form from a button in another form. The form with the button,contracts_all form, has a field ID and I want to open up the form that contains the information with that ID. This second form,contracts, has additional information and has buttons that allow editing of that particular contract. I have managed to get something but it's giving me a 'Run -time error 2489. Form contracts not open' The code is below. Thanks in advance.
我正在尝试从另一个表单中的按钮打开一个表单。带有按钮的表单,contracts_all 表单,有一个字段 ID,我想打开包含该 ID 信息的表单。第二种形式,合同,具有附加信息和允许编辑该特定合同的按钮。我设法得到了一些东西,但它给了我一个“运行时错误 2489。表单合同未打开”代码如下。提前致谢。
Private Sub Command74_Click()
ID = [Forms]!Contracts_all![ID]
DoCmd.GoToRecord acDataForm, "Contracts", ID
End Sub
采纳答案by Johnny Bones
Dim Rs As Recordset
Dim Test As Integer
Dim varBookmark As Variant
DoCmd.OpenForm "Contracts"
Set Rs = Forms!Contracts.RecordsetClone
Rs.FindFirst ("[ID] = '" & Me![ID] & "'")
varBookmark = Rs.Bookmark
Forms!Contracts.Form.Bookmark = varBookmark
If Rs.NoMatch Then
MsgBox "That does not exist in this database."
Else
End If
回答by KuroNeko
I have the answer..thanks all for your help..what i ended up doing was get ID from Contracts_all form and each time I reopen the contracts form.here's my code
我有答案..感谢大家的帮助..我最终做的是从 Contracts_all 表单中获取 ID,每次我重新打开合同表单时。这是我的代码
Private Sub next_Click()
On Error GoTo Err_next_Click
DoCmd.SelectObject acForm, "contracts_all"
DoCmd.GoToControl "ID"
DoCmd.GoToRecord , , acNext
DoCmd.OpenForm "Contracts", , , "ID = " & Forms!contracts_all![ID]
Exit_next_Click:
Exit Sub
Err_next_Click:
MsgBox Err.Description
Resume Exit_next_Click
End Sub