I have one additional question, please humor me if you have the time! :)
I'm not sure if this is even possible, but for part of this project I would like to set two bookmarks - one to show a specific record on my main form, and another to show a specific record on a subform.
The main form shows Building information and the subform shows Contact information for that building (a one to many relationship). I click on an "edit" button on the main form to open a pop-up form for data entry about the building. When I click on the "done" button on this pop-up form, the code above is used in the On-Click event to go back to the specific record on the main form. To edit the contact information I click on an "edit" button on the contacts subform to open a pop-up form for data entry about the contact. When closing this pop-up, I would like to return to the specific building record on the main form, and also go to the specific contact on the subform for which I was entering data in the pop-up form.
I tried to adjust the code above to add a second bookmark, but am getting the error "Object variable or With block variable not set". I've posted the code below. I think the problem might be in in second "FindFirst" line of code, but I'm not sure. I tried to look at the explanation for this bug on support.microso ft.com/kb/316478, but have to admit not understanding it :(
The main form is "frmTabs", the subform is "frmTabContacts ", the pop-up form in this case is "frmEditContact Nm".
Any assistance would be greatly appreciated!!
Bridget
I'm not sure if this is even possible, but for part of this project I would like to set two bookmarks - one to show a specific record on my main form, and another to show a specific record on a subform.
The main form shows Building information and the subform shows Contact information for that building (a one to many relationship). I click on an "edit" button on the main form to open a pop-up form for data entry about the building. When I click on the "done" button on this pop-up form, the code above is used in the On-Click event to go back to the specific record on the main form. To edit the contact information I click on an "edit" button on the contacts subform to open a pop-up form for data entry about the contact. When closing this pop-up, I would like to return to the specific building record on the main form, and also go to the specific contact on the subform for which I was entering data in the pop-up form.
I tried to adjust the code above to add a second bookmark, but am getting the error "Object variable or With block variable not set". I've posted the code below. I think the problem might be in in second "FindFirst" line of code, but I'm not sure. I tried to look at the explanation for this bug on support.microso ft.com/kb/316478, but have to admit not understanding it :(
The main form is "frmTabs", the subform is "frmTabContacts ", the pop-up form in this case is "frmEditContact Nm".
Any assistance would be greatly appreciated!!
Bridget
Code:
'Called from the "Done" button of the pop-up form "frmEditContactNm",
'which was opened using the "edit" button on the main form's ("frmTabs")
'subform called "frmTabContacts".
Private Sub btnDone_Click()
'start error check.
On Error GoTo Err_btnDone_Click
'list variables
Dim rs As DAO.Recordset
Dim rst As DAO.Recordset
Dim intBldgID As Integer
Dim intContactID As Integer
Dim PopUpFrm As String
Dim MainFrm As String
'store IDs from Pop-up form as variables.
'(The control txtBldgID is in a subform on the pop-up form sfrmContBldg and
' the control txtContactID is on the main pop-up form frmEditContactNm)
intBldgID = Forms![frmEditContactNm]![sfrmContBldg].Form![txtBldgID]
intContactID = Me.txtContactID
'define pop-up form variable
PopUpFrm = "frmEditContactNm"
'close pop-up form
DoCmd.Close acForm, PopUpFrm
'define main form variable.
MainFrm = "frmTabs"
'open main form
DoCmd.OpenForm MainFrm
'set recordset clone on main form
Set rs = Forms(MainFrm).Recordset.Clone
'find record that matches stored ID
rs.FindFirst "[BldgID] = " & intBldgID
'set bookmark on main form to the record that matches the stored record from the pop-up form.
Forms(MainFrm).Bookmark = rs.Bookmark
'set focus to frmTabContacts
Forms!frmTabs.frmTabContacts.SetFocus
'find record that matches stored ID
rst.FindFirst "[ContactID] = " & intContactID
'set bookmark on main form to the record that matches the stored record from the pop-up form.
Forms!frmTabs.frmTabContacts.Bookmark = rs.Bookmark
'Exit the sub
Exit_btnDone_Click:
Exit Sub
'Exit the error check.
Err_btnDone_Click:
MsgBox Err.Description
Resume Exit_btnDone_Click
End Sub
Comment