Open a form using ID from a different form in Access 2010 using vba

若如初见. 提交于 2019-12-07 16:17:05

问题


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.

Private Sub Command74_Click()
    ID = [Forms]!Contracts_all![ID]
    DoCmd.GoToRecord acDataForm, "Contracts", ID
End Sub

回答1:


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



回答2:


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

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


来源:https://stackoverflow.com/questions/17046407/open-a-form-using-id-from-a-different-form-in-access-2010-using-vba

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