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

Home Posts Topics Members FAQ

From Subform, refer to a control on a Mainform

79 New Member
I read a thread about referring to a control on a Subform with the following format.

Expand|Select|Wrap|Line Numbers
  1. Forms![Your Main Form Name]![Subform Name].Form![Subform control name]
  2.  
How to work on opposite way, referring to a control on a Mainform from SubForm?

I tried using the same format, except using Mainform control name inside the last bracket, but it doesn’t work.

Thanks.
Oct 26 '11 #1
8 16392
Seth Schrock
2,965 Recognized Expert Specialist
I believe that this should work:

Expand|Select|Wrap|Line Numbers
  1. Forms![main form name here]![control name here]
I know that I have had to do exactly what you are describing, but I don't remember which database it was, but I do believe that this would work. Let me know.
Oct 27 '11 #2
NeoPa
32,584 Recognized Expert Moderator MVP
When you're already within a module associated with one of these forms then you really don't want to use the fully specified version in your references. The article does give other options and explain how and when to use them.

When referring up, as in from Sub Form to Main Form, Me.Parent should be the base of your reference. The control name follows from there.
Oct 27 '11 #3
Joe Y
79 New Member
NeoPa,

Could you please point out the link to the article you referred to? I searched this subject by key words. The closest one I found was a thread dated in April this year. There was no discussion of other options.

Thanks.
Oct 27 '11 #4
NeoPa
32,584 Recognized Expert Moderator MVP
My mistake Joe.

The article is Referring to Items on a Sub-Form.

It doesn't cover referring back to the main form, but I covered that the correct way in post #3.
Oct 27 '11 #5
Joe Y
79 New Member
The codes below work, but I need further helps.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Cbo_ProductCode_AfterUpdate()
  2.  
  3. Dim strFilter As String
  4.  
  5. strFilter = "([ordh_cust_no]='" & Forms![F_Order_Header]![txt_ordh_cust_no] & "') AND " & _
  6.  "([ordd_stock_no]='" & Me.Cbo_ProductCode & "')"
  7.  
  8. End Sub
  9.  
The next challenge is that this Subform is embedded in two different Mainforms. When user clicks the combobox in the Subform, the program should perform same results disregard which Mainform user is in. To do so, I use the following codes to return Mainform names instead of spelling out specific Mainform name in the code.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Cbo_ProductCode_AfterUpdate()
  2.  
  3. Dim strFilter As String
  4. Dim frmCurrentForm As Form
  5. Set frmCurrentForm = Screen.ActiveForm
  6. Dim strFormName As String
  7. strFormName = frmCurrentForm.Name
  8.  
  9. MsgBox (strFormName)
  10.  
  11. strFilter = "([ordh_cust_no]='" & Forms!strFormName![txt_ordh_cust_no] & "') AND " & _
  12.  "([ordd_stock_no]='" & Me.Cbo_ProductCode & "')"
  13.  
  14. End Sub
  15.  
The message box does show the correct Mainform name in the popup window, but after clicking OK button, it follows with an error message saying Access cannot find the form ‘strFormName’. I have tried to include the strFormName inside brackets or double quotes, that didn’t work, either.

Please guide what part of the code is wrong.

Thanks.
Oct 27 '11 #6
NeoPa
32,584 Recognized Expert Moderator MVP
You have a few problems in there Joe.

In most cases using the code suggested by Seth is just not too clever. A bit clumsy but it will work if you know the name of the main form already.

In this case, where that information isn't known, it makes sense to use the more appropriate method suggested in post #3 which is to use the Me.Parent reference.

PS. I notice from your posted code that you do nothing with strFilter once you've set it up. Is this simply because you haven't got that far yet?

PPS. I'm going to have to reset Seth's Best Answer post I'm afraid. It's good thinking but just not quite correct for the question. I've avoided it thus far as I had no wish to discourage Seth in any way, but unfortunately it could mislead people searching for similar problems.
Oct 27 '11 #7
Joe Y
79 New Member
Oops! Sorry, I missed one important line. The missing line is the "Call DoCmd.OpenForm" in the working code below.

Also, thanks for suggesting the Me.Parent reference method. This would allow my reference task a lot more flexible.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Cbo_ProductCode_AfterUpdate()
  2.  
  3. Dim strFilter As String
  4.  
  5. strFilter = "([ordh_cust_no]='" & Me.Parent![txt_ordh_cust_no] & "') AND " & _
  6.  "([ordd_stock_no]='" & Me.Cbo_ProductCode & "')"
  7.  
  8.  
  9. Call DoCmd.OpenForm(FormName:="F_Ord_History", View:=acFormDS, WhereCondition:=strFilter)
  10.  
  11. End Sub
  12.  
However, could you please still let me know, using my previous broken codes as example, how to make Access know the program is calling the Mainform name in line # 11 of previous post and use it as part of the filter string?

Thanks.
Oct 27 '11 #8
NeoPa
32,584 Recognized Expert Moderator MVP
Joe Y:
Oops! Sorry, I missed one important line. The missing line is the "Call DoCmd.OpenForm" in the working code below.
That's why we insist you use Copy/Paste etc (See When Posting (VBA or SQL) Code) when you post code. Don't worry about previous posts but please make sure you follow the guidance in all future posts.

Joe Y:
However, could you please still let me know, using my previous broken codes as example, how to make Access know the program is calling the Mainform name in line # 11 of previous post and use it as part of the filter string?
This bit's a little weird. It seems to me you already have a working bit of code for that (Lines #5 & #6) which appear to be correct. What else would you want? I see no sensible place to use the name of the main form as it's totally unrequired when coding the reference properly (As it appears to me you have already done).
Oct 27 '11 #9

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

Similar topics

1
5973
by: Spurry Moses | last post by:
Hi, I'm converting a project from C++Builder to C# and I just need to copy my class design across. It's looking good so far. To stick with the design I want to inherit from a ComboBox control (ie MyComboBox). I don't need to do anything flash with it, just add a few properties and methods. I'd almost solved this while writing this post but I'll just confirm what I'm doing is OK. It was a bit awkward in Visual Studio because all of...
3
295
by: Christopher Young | last post by:
I have several user controls on a page and I am trying to get information out of them. The postback is being caused on the aspx page and not in the user control. I have tried using a property but I keep getting a message that the object is not referenced. What I am trying to do is be information from text boxes and insert them into a new row in a dataset. The application has several tabs of information. I have a button set up so they...
1
2087
by: abjork | last post by:
I have a aspx page with two user controls. One of them holds some properties that I would like to set from the other user control. How do I do that I keep getting "Object reference not set to an instance of an object." when I declare the first user control like this from within the second UC Public formStandard As PIC.FormStandar .... formStandard.Market =
6
7813
by: Sakharam Phapale | last post by:
Hi All, How to fill one ComboBox from other ComboBox control? 1) Only setting the reference does the trick but doesn't show items in control. If you see in immediate window, it shows the item count correctly
4
1692
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project that build a class library dll. Here we have a class called C We have one dependency and that is from the user control to the class library because in the constructor for class B in the user control we have a call to
5
1949
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project that build a class library dll. Here we have a class called C We have one dependency and that is from the user control to the class library because in the constructor for class B in the user control we have a call to
10
1995
by: Roy | last post by:
How do I read the value of an html input control from inside a javascript user control? An aspx page contains a user control that attempts to read a value from an html input control in the aspx page. For example: In the aspx page, the control is defined as: <input id="txtTMOStart" runat="server" name="txtTMOStart" type="TEXT"
40
4054
by: Rotor | last post by:
Hello, I have a subform that displays hull# and WO#. I would like for those fields to populate when the user opens up a form that requires them, after clicking on the hull#. So, I setup the hull# field to open FrmJobAccomplished on click. Then when FrmJobAccomplished opens, I would like for Hull# and WO# to be populated from subform. Make sense?
3
1431
by: Peter | last post by:
Hi, I have a project with an MDI parent form (Main), which can contain any number of MDI children (Document). The Document form contains several user controls, designed as separate projects and referenced from the main project. I originally had one user control doing some dataset loading on its own, but now I need the same dataset initialized in the same way in two different places, so I decided to put it in the MDI parent form. Now,...
8
9771
by: OldBirdman | last post by:
This should be so, so simple I hesitate to ask. I have a Form named "fNavButtons" used as a SubForm in control named "subformNavButtons". subformNavButtons is a control on my main form named "fAAA". fNavButtons has 2 CommandButtons, cmdNextRec and cmdPrevRec. These are on a subform to allow an AutoRepeat to continue when form fAAA gets another record. If I am at the first record, I want cmdPrevRec.Enabled = False, and if I am at the...
0
9665
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10541
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10585
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,...
0
10249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7785
isladogs
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...
0
5645
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...
0
5818
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4007
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3108
bsmnconsultancy
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.