473,836 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it Possible to Reference a SubForm in DoCmd.SearchFor Record?

Seth Schrock
2,965 Recognized Expert Specialist
I was able to figure out the following code, and it works:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command4_Click()
  2. DoCmd.OpenForm "frmLoans"
  3. DoCmd.SearchForRecord , , acFirst, "LoanID = " & Me.txtLoanID
  4. Forms!frmLoans!sfrmAppraisals.SetFocus
  5. DoCmd.SearchForRecord , , acFirst, "AppraisalID = " & Forms!frmSearch!txtAppraisalID
  8. End Sub
I thought that I would be able to replace lines 4 & 5 with the following:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.SearchForRecord acDataForm, "sfrmAppraisals", acFirst, "AppraisalsID = " & Me.txtAppraisalID
but it said that sfrmAppraisals wasn't open on the error messages. So I thought that I would try
Expand|Select|Wrap|Line Numbers
  1. DoCmd.SearchForRecord acDataForm, "frmLoans!sfrmAppraisals.Form", acFirst, "AppraisalsID = " & Me.txtAppraisalID
Same Problem. Is there a way to do this?

It is really no big deal, but I thought it would be a little more efficient using only one line of code instead of two. The form opens on the slow side anyway so I'm trying to eliminate any unnecessary steps in the code.
Dec 10 '12 #1
21 7916
12,516 Recognized Expert Moderator MVP
The form isn't considered as open if it's a subform.
Dec 10 '12 #2
Seth Schrock
2,965 Recognized Expert Specialist
So my "more efficient" idea won't work?
Dec 10 '12 #3
12,516 Recognized Expert Moderator MVP
Probably not. It's the same if you try to Close the form. It will tell you the form is not open as opposed to "closing" the subform.
Dec 10 '12 #4
5,501 Recognized Expert Moderator Expert
If you are using either DAO or ADO recordset then you should be able to use one of these:

In the click_event of a command button on the PARENT form:

If [AppraisalID] is datatype text/string:
Me.YourSubFormN ameHere.Form.Re cordset.FindFir st "AppraisalI D = '" & Forms!frmSearch !txtAppraisalID &"'"

If [AppraisalID] is datatype numeric:
Me.YourSubFormN ameHere.Form.Re cordset.FindFir st "AppraisalI D = " & Forms!frmSearch !txtAppraisalID

You can also use the movefirst, movelast, etc...

other than using your field name and the "YourSubFormNam eHere" these are taken directly from one of my production databases.
Dec 10 '12 #5
Seth Schrock
2,965 Recognized Expert Specialist
@Z My problem is that the code will be triggered from an event on a totally different form than the parent or child form.

As I said before, I do have code that works that doesn't seem too bulky (to me) so I can live with that.
Dec 11 '12 #6
32,584 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. DoCmd.SearchForRecord acDataForm, "sfrmAppraisals", acFirst, "AppraisalsID = " & Me.txtAppraisalID
Looking at your code, and checking the online Help page as I don't use Access 2007, it seems clear that you have everything pretty well OK except that the Help page doesn't explain clearly what the parameters are exactly, and what you can expect to use. Reading between the lines it seems that acDataForm is expecting a form from the Forms() collection. A collection which subforms are never added to of course. A bit of a naff interface to introduce after this many years of experience IMHO. It would appear that you can still use the procedure by doing things the awkward way, but one of the alternatives already suggested may be an easier route. Who needs clumsy code? Who needs to be forced into using clumsy code by the designers of the system?
Dec 11 '12 #7
Seth Schrock
2,965 Recognized Expert Specialist
I tried leaving out the acDataForm so that it would go to its default (acActiveDataOb ject or something like that) and it still didn't work.

So are you meaning that you think my code is clumsy (the code that I was planning on using is in the first block of code in the OP if that wasn't clear)?
Dec 11 '12 #8
32,584 Recognized Expert Moderator MVP
The clumsiness I'm referring to is the same clumsiness you recognised when you decided to try to do it in a single call. That was showing good instincts. The fact that Access doesn't support tidier code when you try to use it is certainly not a reflection on you.

In the circumstances, your original code seems to be about the best available (without changing your approach to use a different call).
Dec 11 '12 #9
Seth Schrock
2,965 Recognized Expert Specialist
Okay. I glad that I have finally came up with some code on my own that is actually a good way to do it. I am always scared that I'm doing something in a poor way when I try something new, especially when it looks bigger than it needs to be. I always like to check to make sure that I'm not doing things the hard way because I know how easy it is to really mess things up by not doing them the proper way. There are reasons for the rules, but I don't always know what the rules are. This gives me some hope that I am starting to really learn from the experts here.
Dec 11 '12 #10

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

Similar topics

by: Max Harvey | last post by:
Hi, I made up a nice little form which had its own sub form in it. I made a litle VB code so that when I pressed a button it would move form the form (frmConference) to the subform (frmBookingBookingBased), start a new record, and copy some values form the form into some fields in the subform, and then leave the cursor sitting (in focus) at the begining of the subform.
by: Geoff | last post by:
I have a form with a subform. The latter contains a calculated field, , derived from a query. In the footer of this subform is an unbound text box whose control source = SUM() . works fine I want to save the value in into a variable in the main form called . This is bound to Tbl_Products
by: (PeteCresswell) | last post by:
I've got a parent form and three subforms. Two of them work A-OK. For the third one, in the Immediate window: ----------------------------------------- ?Me.subDeal.Name subDeal ?Me.subDeal.SourceObject
by: rhc | last post by:
access 2000 I have a tab control with 2 pages and one subform on each. On parent form P from the form_current() event of subform A I cant seem to refer to subform B. msgbox forms!.form.name works
by: abprules | last post by:
I am trying to tab from my header to my detail section in a form that includes a tabcontrol form. It is not working. Can anybody suggest something. I have tried the following: Add a text box to the header section, make it last in the tab order of that section, and set these properties: Name: txtTransferToDetail Visible: Yes
by: anansi | last post by:
Hi all I have a very simple problem but i am highly confused. firstly, a google web search of "DoCmd.Searchforrecord" returns nothing. i've been starting to get suspicious why no one else is interested in this function but me, but here goes: sID = Me.ShiftID '--- this is the subforms field, ShiftID ParentsID = Me.Parent.ShiftID '---this is shift viewer's field, ShiftID DoCmd.SearchForRecord acDataForm, "shift...
by: Coll | last post by:
I have a form with a subform on it. On my main form, you select an employee id number and the top portion of form fills in with data, and the bottom portion of the form,which is a subform, lists existing records there are for that employee (one to many relationship). How can I set up my main form, so the user can select one of the records on the subform and retain that recordid number for use in opening a new form and displaying the that...
by: Lebbsy | last post by:
After displaying search results, I want to be able to double click the identity number field and then the input form SubmissionDetails becomes the display form for the results of the data matching value of the selected identity number. With my code below I get a data type mismatch error. Please help me....... Private Sub IdentityNumber_Click() On Error GoTo IdentityNumber_Click_Err On Error Resume Next If (Form.Dirty) Then ...
by: Daniel Owino | last post by:
Hi I'm trying to add a new record to a subform called itemsreceived_subform, using a command button. I can't get the clear difference between the subform control, and the subform itself. My code is as follows: Private Sub cmdadd_Click() If Me!Itemsreceived_subform.Form.Dirty Then Me!Itemsreceived_subform.Form.Dirty = False End If Me!.SetFocus ' This is the name of the subform
by: munkee | last post by:
Hi all, I am having some trouble, I am trying to create an advanced search form which will open up as a popup from my main search from. I am using the Allen Browne method of creating the where string however I am setting the recordsource of the subform with a constructed sql string, not filtering. My main form contains a subform which my basic search selects perfectly. However I cant seem to be able to get my advanced search to point...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.