By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,045 Members | 1,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,045 IT Pros & Developers. It's quick & easy.

Opening a record in parent form from a subform

P: 4
I have a subform of all the customers for the day (limited info). I want to open the specific record on the parent form by clicking an action button, on a specific record, on the subform. I have the following Event Procedure for the action button. When I run the procedure, I get a Run Time Error (3021), No Current Record. What am I doing wrong?
Expand|Select|Wrap|Line Numbers
  1. Dim rs As Object
  2. Dim strLinkValue As String
  4.     strLinkValue = Me![CustID].Value     'Name of Link Field On Subform
  5.     Set rs = Forms!frmNextCustomerContractors.Recordset.Clone     'Name of the Main Form
  6.     rs.FindFirst "[CustID] = '" & strLinkValue & "'"     'Name of Link Field on main form
  7.     Forms!frmNextCustomerContractors.Bookmark = rs.Bookmark     'Main Form
1 Week Ago #1
Share this Question
Share on Google+
6 Replies

Expert Mod 15k+
P: 31,419
Your first, and probably main, problem is referring to .Recordset.Clone instead of .RecordsetClone.
1 Week Ago #2

P: 4
I changed .Recordset.Clone to .RecordsetClone
I'm receiving the same error (No Current Record) on line 7.
Any help would be appreciated.
1 Week Ago #3

Expert Mod 2.5K+
P: 3,205
An easier, and more direct approach to this may be simply to filter the parent form by your Search Criteria:

Expand|Select|Wrap|Line Numbers
  1. With Me.Parent.Form
  2.     .Filter = "[CustID] = '" & strLinkValue & "'"
  3.     .FilterOn = True
  4. End With
However, something tells me that your solution is not going to be so straightforward as this (but this is just a hunch).

At this point, both NeoPa and I are both stabbing int he dark, because we don't know how your tables are structured, nor do we know how your Main Form and Sub-Forms are related (if at all).

Without more clear information, we can't really troubleshoot this toward a more accurate solution.
1 Week Ago #4

Expert Mod 15k+
P: 31,419
As Twinny says, we're working a little in the dark here. Not that your question is a poor one, just that it's often difficult to know what information is required when you aren't sure of what's wrong. Let's see what we can determine at this point anyway.

First off - I too would recommend the approach Twinny suggests. Too many people overlook this, more simple, approach simply because it doesn't occur to them.

That said, we always like to answer the question put even in situations such as these where there's a much better approach available. In this case I believe you may be trying to use Bookmarks from two quite different Recordsets in your code and that won't work. It can be used between a Form's Recordset and the same Form's RecordsetClone properties, but a Bookmark is a complicated item and depends heavily on the Recordset it's from. Trying to transport that across to a different Recordset simply isn't supported.

I hope that resolves all your issues but please let us know. We're both happy to help further (I know Twinny well enough by now to be confident to say that.) if we can.
1 Week Ago #5

P: 4
I'm getting closer. The following code works but only if the CustID field, on the parent form is visible. I don't want it visible. Any help is appreciated.
Expand|Select|Wrap|Line Numbers
  1. Dim strLinkValue As String
  3.     strLinkValue = Me![CustID].Value     'Name of Link Field On Subform
  4.     Forms.Item("frmNextCustomerContractors").RecordSource = "qryNextCustomerContractorsToday"
  5.     MsgBox strLinkValue
  6.     DoCmd.GoToControl "CustID"
  7.     DoCmd.FindRecord strLinkValue, , True, , True
1 Week Ago #6

Expert Mod 15k+
P: 31,419
Well, it seems that you've ignored the advice about using a filter instead of going to the record, and haven't explained why. That's disappointing. If we're to work together then we need to understand what you're doing and why. Too many guesses along the road is not good for any of us.

That said, we could proceed anyway except for the fact we have no indication of what isn't working. You simply say it isn't. I'd guess that line #6 would cause an issue. You can't set the focus to a Control that isn't visible. That wouldn't make sense. It's hard even to guess why you have that in there. Sometimes we can guess based on experience and simple logic, but in this case there appears to be none of the latter so I'm lost.

Perhaps if you could explain your thinking more fully we would be in a better place to understand where you're coming from and why you do things the way you do. As a bare minimum, if you have something that isn't working, you should explain exactly what happens and where in the code it happens.
1 Week Ago #7

Post your reply

Sign in to post your reply or Sign up for a free account.