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.microsoft.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 "frmEditContactNm".
Any assistance would be greatly appreciated!!
Bridget -
'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
-
6 6891
Hi Bridget. You have not set a value for your second Recordset - rst (a confusing choice of name when the other one is called rs) - hence the object not set error. Because of the missing Set statement you have not actually cloned the subform's recordset at all so far.
I'm not sure that when you fix all this it will do what you want it to do, as subforms are normally bound to a value in the main form, which I think will work against trying to go to a specific record in the subform using recordsetclone, but feel free to experiment here!
-Stewart
Hi Bridget. You have not set a value for your second Recordset - rst (a confusing choice of name when the other one is called rs) - hence the object not set error. Because of the missing Set statement you have not actually cloned the subform's recordset at all so far.
I'm not sure that when you fix all this it will do what you want it to do, as subforms are normally bound to a value in the main form, which I think will work against trying to go to a specific record in the subform using recordsetclone, but feel free to experiment here!
-Stewart
Thank you for your response, Stewart. I realized the error in not having set a value for the second recordset after posting this. Duh! (and yes, rs vs rst is not very clear - I switched it to "rsm" and "rss" for rs main and rs sub respectively - not much better, but...)
Unfortunately, I still get an error. I'm wondering the same thing as you, whether or not its possible to do a double bookmark - one for a form and another for the subform... I will keep experimenting and post if I come up with a solution. In the mean time, if anyone has other ideas of how I can go to a specific record on a subform of a specific record on a main form, let me know!!
thx
Bridget
ADezii 8,834
Recognized Expert Expert
Thank you for your response, Stewart. I realized the error in not having set a value for the second recordset after posting this. Duh! (and yes, rs vs rst is not very clear - I switched it to "rsm" and "rss" for rs main and rs sub respectively - not much better, but...)
Unfortunately, I still get an error. I'm wondering the same thing as you, whether or not its possible to do a double bookmark - one for a form and another for the subform... I will keep experimenting and post if I come up with a solution. In the mean time, if anyone has other ideas of how I can go to a specific record on a subform of a specific record on a main form, let me know!!
thx
Bridget
You could always use Public Variables initialized in the btnDone_Click() Event to store relevant values in both the Main and Sub-Forms, then use a pair of DoCmd.FindRecords to navigate to the correct Record in first the Main, and then the Sub_form.
You could always use Public Variables initialized in the btnDone_Click() Event to store relevant values in both the Main and Sub-Forms, then use a pair of DoCmd.FindRecords to navigate to the correct Record in first the Main, and then the Sub_form.
Thanks for the idea, ADezii! I will give this a try.
Bridget
Thanks for the idea, ADezii! I will give this a try.
Bridget
Hello all,
Before trying ADezii's idea, I gave the bookmark idea one more try and... I got it to work! (amazing - I almost feel like I'm starting to get this. At least until the next hiccup!)
I'm posting the code for people's reference. (A huge thank you to Allen Browne - I was able to use a suggestion made by him on another website and adjust it to make it work for me)
The code below is to set two bookmarks, one on a main form and the second on a subform on the main form. The code is called from the OnClick event of a Pop up form (opened by clicking on a button on the main form). The code first captures the current record (BldgID) from the main form and bookmarks it. Then it captures the current record (ContactIID) from the popup form and bookmarks this record on the main form's subform.
I hope it is of use to others.
Bridget -
Private Sub btnDone_Click()
-
-
'start error check.
-
On Error GoTo Err_btnDone_Click
-
-
'list variables
-
Dim rs As DAO.Recordset
-
Dim strWhere As String
-
Dim strMain As String
-
Dim strPopUp As String
-
-
'FIRST FIND RECORDSET IN MAIN FORM:
-
-
'capture the BldgID from the main form.
-
strWhere = "BldgID = " & Forms!frmTabs.txtBldgID
-
-
'define the main form variable.
-
strMain = "frmTabs"
-
-
're-open the main form.
-
DoCmd.OpenForm strMain
-
-
'set recordset clone on the main form.
-
Set rs = Forms(strMain).Recordset.Clone
-
-
'find record that matches stored ID.
-
rs.FindFirst strWhere
-
-
'set bookmark on main form to the record that matches the stored ID.
-
Forms(MainFrm).Bookmark = rs.Bookmark
-
-
'clear the recordset variable.
-
Set rs = Nothing
-
-
'SECOND FIND RECORDSET IN SUBFORM:
-
-
-
'capture the ContactID from the sub form.
-
strWhere = "ContactID = " & Me.txtContactID
-
-
'set recordset clone on the main form's subform.
-
With Forms!frmTabs.frmTabContacts.Form
-
Set rs = .RecordsetClone
-
-
''find record that matches stored ID.
-
rs.FindFirst strWhere
-
.Bookmark = rs.Bookmark
-
End With
-
-
'define the pop-up form variable.
-
strPopUp = "frmEditContactNm"
-
-
'close the pop-up form.
-
DoCmd.Close acForm, strPopUp
-
-
'Exit the sub
-
Exit_btnDone_Click:
-
Exit Sub
-
-
'Exit the error check.
-
Err_btnDone_Click:
-
MsgBox Err.Description
-
Resume Exit_btnDone_Click
-
-
End Sub
-
ADezii 8,834
Recognized Expert Expert
Hello all,
Before trying ADezii's idea, I gave the bookmark idea one more try and... I got it to work! (amazing - I almost feel like I'm starting to get this. At least until the next hiccup!)
I'm posting the code for people's reference. (A huge thank you to Allen Browne - I was able to use a suggestion made by him on another website and adjust it to make it work for me)
The code below is to set two bookmarks, one on a main form and the second on a subform on the main form. The code is called from the OnClick event of a Pop up form (opened by clicking on a button on the main form). The code first captures the current record (BldgID) from the main form and bookmarks it. Then it captures the current record (ContactIID) from the popup form and bookmarks this record on the main form's subform.
I hope it is of use to others.
Bridget -
Private Sub btnDone_Click()
-
-
'start error check.
-
On Error GoTo Err_btnDone_Click
-
-
'list variables
-
Dim rs As DAO.Recordset
-
Dim strWhere As String
-
Dim strMain As String
-
Dim strPopUp As String
-
-
'FIRST FIND RECORDSET IN MAIN FORM:
-
-
'capture the BldgID from the main form.
-
strWhere = "BldgID = " & Forms!frmTabs.txtBldgID
-
-
'define the main form variable.
-
strMain = "frmTabs"
-
-
're-open the main form.
-
DoCmd.OpenForm strMain
-
-
'set recordset clone on the main form.
-
Set rs = Forms(strMain).Recordset.Clone
-
-
'find record that matches stored ID.
-
rs.FindFirst strWhere
-
-
'set bookmark on main form to the record that matches the stored ID.
-
Forms(MainFrm).Bookmark = rs.Bookmark
-
-
'clear the recordset variable.
-
Set rs = Nothing
-
-
'SECOND FIND RECORDSET IN SUBFORM:
-
-
-
'capture the ContactID from the sub form.
-
strWhere = "ContactID = " & Me.txtContactID
-
-
'set recordset clone on the main form's subform.
-
With Forms!frmTabs.frmTabContacts.Form
-
Set rs = .RecordsetClone
-
-
''find record that matches stored ID.
-
rs.FindFirst strWhere
-
.Bookmark = rs.Bookmark
-
End With
-
-
'define the pop-up form variable.
-
strPopUp = "frmEditContactNm"
-
-
'close the pop-up form.
-
DoCmd.Close acForm, strPopUp
-
-
'Exit the sub
-
Exit_btnDone_Click:
-
Exit Sub
-
-
'Exit the error check.
-
Err_btnDone_Click:
-
MsgBox Err.Description
-
Resume Exit_btnDone_Click
-
-
End Sub
-
Nice job, and thanks for posting the solution.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: chris vettese |
last post by:
I've been having trouble with this for a long time. I have a form
that has many subforms. In the subforms I have unbound text boxes in
the footer that sum a field. I want to Display this sum on...
|
by: William Wisnieski |
last post by:
Hello Everyone,
Access 2000
I have a main form with a continuous subform. On the main form I have a
text field called . It gets populated based on what the user
selects in a field on the...
|
by: Susan |
last post by:
I have a bound form and subform and am trying to enter the data in both forms
programatically. The Linkmaster and Linkchild properties are set. My intent is
to be able to look at the data before it...
|
by: Dave Boyd |
last post by:
Hi,
I have two very similar forms each with a subform. The main form gets
a few fields from the user and passes this back to a query that the
subform is bound to. The requery is done when the...
|
by: Darryl Kerkeslager |
last post by:
I don't do much with subforms - in fact I've deliberately avoided them - but
....
I have a tab control that will contain several subforms, each bound to a
separate table, and each table/subform...
|
by: origin197511 |
last post by:
Hello all...
I'm having an issue with MSAccess 2000. I have a Form that holds
records of my cartridge loads for a rifle and a subform that lists all
groups that have been fired with that load. ...
|
by: NBruch |
last post by:
Ok let me explain what im trying to do:
i need a combo box which needs to be linked to a listbox (or combo box
doesnt matter which really) then the listbox should bring up the record
in a...
|
by: Tim |
last post by:
Hi, has anyone experienced a spontaneous loss of a subform bookmark
(i.e. resetting to the first record), when the computer is idle.
I used to have a problem in NT4 when doing a couple of...
|
by: deedeem |
last post by:
Hi there,
I am having trouble getting all my records to be placed into my WORD document from my ACCESS form. I have a form with a subform displayed and a control button that executes a macro. The...
|
by: Gord |
last post by:
Is it possible to extract the bookmark using an SQL query?
I'm using A2007 and have a select query used as the recordsource for a
subform. The query pulls out those records that match whatever...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |