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
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
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