473,796 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

focus from main form to sub form

Stu
Hi,
I have a combobox who's values change the recordsource of the form.
Within this form, there is a subform, whos records also need to change
pending the value in the combobox. I am able to get the main forms
values to change, but not the subform. I've only been using Access 97
for about a month now, so it might be fairly simple. Here is my code:

Private Sub combo1_Change()
If Me.combo1.Value = "Standard Procedures" Then
Me.RecordSource = "tbl_stdPro c"
ElseIf Me.combo1.Value = "Policy" Then
Me.RecordSource = "tbl_policy "
ElseIf Me.combo1.Value = "Process Description" Then
Me.RecordSource = "tbl_ProcDe sc"
ElseIf Me.combo1.Value = "Program Description" Then
Me.RecordSource = "tbl_ProgDe sc"
ElseIf Me.combo1.Value = "Training Program" Then
Me.RecordSource = "tbl_TrainP rog"
ElseIf Me.combo1.Value = "Qualificat ion" Then
Me.RecordSource = "tbl_Qual"
ElseIf Me.combo1.Value = "Standard / Specification" Then
Me.RecordSource = "tbl_StdSpe c"
End If
' Everything up to this point works fine. The problem starts below

Me![frm_Type_sub].SetFocus
If Me.combo1.Value = "Standard Procedures" Then
Me.RecordSource = "tbl_stdProc_su b"
ElseIf Me.combo1.Value = "Policy" Then
Me.RecordSource = "tbl_policy_sub "
ElseIf Me.combo1.Value = "Process Description" Then
Me.RecordSource = "tbl_ProcDesc_s ub"
ElseIf Me.combo1.Value = "Program Description" Then
Me.RecordSource = "tbl_ProgDesc_s ub"
ElseIf Me.combo1.Value = "Training Program" Then
Me.RecordSource = "tbl_TrainProg_ sub"
ElseIf Me.combo1.Value = "Qualificat ion" Then
Me.RecordSource = "tbl_Qual_s ub"
ElseIf Me.combo1.Value = "Standard / Specification" Then
Me.RecordSource = "tbl_StdSpec_su b"
End If
End Sub
From searching the archives, it seems like I need to set the focus to

the form on one line, then to the object on another, but I'm not sure
how to do so.
So to sum up my problem: Using a combobox in a form, how do I change
the subforms recordsource?

Thanks in advance!
Stuart K

Nov 13 '05 #1
7 2387
Stu wrote:
Hi,
I have a combobox who's values change the recordsource of the form.
Within this form, there is a subform, whos records also need to change
pending the value in the combobox. I am able to get the main forms
values to change, but not the subform. I've only been using Access 97
for about a month now, so it might be fairly simple. Here is my code:

Private Sub combo1_Change()
If Me.combo1.Value = "Standard Procedures" Then
Me.RecordSource = "tbl_stdPro c"
ElseIf Me.combo1.Value = "Policy" Then
Me.RecordSource = "tbl_policy "
ElseIf Me.combo1.Value = "Process Description" Then
Me.RecordSource = "tbl_ProcDe sc"
ElseIf Me.combo1.Value = "Program Description" Then
Me.RecordSource = "tbl_ProgDe sc"
ElseIf Me.combo1.Value = "Training Program" Then
Me.RecordSource = "tbl_TrainP rog"
ElseIf Me.combo1.Value = "Qualificat ion" Then
Me.RecordSource = "tbl_Qual"
ElseIf Me.combo1.Value = "Standard / Specification" Then
Me.RecordSource = "tbl_StdSpe c"
End If
' Everything up to this point works fine. The problem starts below

Me![frm_Type_sub].SetFocus
If Me.combo1.Value = "Standard Procedures" Then
Me.RecordSource = "tbl_stdProc_su b"
ElseIf Me.combo1.Value = "Policy" Then
Me.RecordSource = "tbl_policy_sub "
ElseIf Me.combo1.Value = "Process Description" Then
Me.RecordSource = "tbl_ProcDesc_s ub"
ElseIf Me.combo1.Value = "Program Description" Then
Me.RecordSource = "tbl_ProgDesc_s ub"
ElseIf Me.combo1.Value = "Training Program" Then
Me.RecordSource = "tbl_TrainProg_ sub"
ElseIf Me.combo1.Value = "Qualificat ion" Then
Me.RecordSource = "tbl_Qual_s ub"
ElseIf Me.combo1.Value = "Standard / Specification" Then
Me.RecordSource = "tbl_StdSpec_su b"
End If
End Sub
From searching the archives, it seems like I need to set the focus to the form on one line, then to the object on another, but I'm not sure
how to do so.
So to sum up my problem: Using a combobox in a form, how do I change
the subforms recordsource?


From the MainForm you could enter
'Me![frm_Type_sub].SetFocus no need for this
If Me.combo1.Value = "Standard Procedures" Then
Forms!MainForm! SubForm.Form.Re cordsource = "tbl_stdProc_su b"
elseif Me.combo1.Value = "Policy" Then
Me("SubFormName ").Form.Records ource = "tbl_policy_sub "
..........

That's 2 ways to reference the subform. You might need to requery the
subform.


Thanks in advance!
Stuart K

Nov 13 '05 #2
Stu
I changed my code to your suggestion, but I get the following message:

If Me.combo1.Value = "Standard Procedures" Then
Me("frm_Type_su b").Form.Record Source = "tbl_StdProc_su b" ' **

and

If Me.combo1.Value = "Standard Procedures" Then
Forms!frm_Type! frm_Type_sub.Fo rm.RecordSource = "tbl_stdProc_su b"
' **

but on both I got the message:
Runtime error 2465
MS Access can't find the field 'tbl_Type_sub' referred to in your
expression. ( on line ** )

I also tried the following code:
If Me.combo1.Value = "Standard Procedures" Then
Me.frm_Type_sub .FormRecordSour ce = "tbl_StdProc_su b" ' **

Error Message:
Compile error: method or data member not found. (refers to line **)

any suggestions? I double checked to make sure the form names were
correct, and that the code matches. On the first two codes, it gave
the error of not finding field 'frm_Type_sub' but it should be finding
a form, not a field.

thanks!

Nov 13 '05 #3
Stu
I changed my code to your suggestion, but I get the following message:

If Me.combo1.Value = "Standard Procedures" Then
Me("frm_Type_su b").Form.Record Source = "tbl_StdProc_su b" ' **

and

If Me.combo1.Value = "Standard Procedures" Then
Forms!frm_Type! frm_Type_sub.Fo rm.RecordSource = "tbl_stdProc_su b"
' **

but on both I got the message:
Runtime error 2465
MS Access can't find the field 'tbl_Type_sub' referred to in your
expression. ( on line ** )

I also tried the following code:
If Me.combo1.Value = "Standard Procedures" Then
Me.frm_Type_sub .FormRecordSour ce = "tbl_StdProc_su b" ' **

Error Message:
Compile error: method or data member not found. (refers to line **)

any suggestions? I double checked to make sure the form names were
correct, and that the code matches. On the first two codes, it gave
the error of not finding field 'frm_Type_sub' but it should be finding
a form, not a field.

thanks!

Nov 13 '05 #4
Stu wrote:
I changed my code to your suggestion, but I get the following message:

If Me.combo1.Value = "Standard Procedures" Then
Me("frm_Type_su b").Form.Record Source = "tbl_StdProc_su b" ' **

and

If Me.combo1.Value = "Standard Procedures" Then
Forms!frm_Type! frm_Type_sub.Fo rm.RecordSource = "tbl_stdProc_su b"
' **

but on both I got the message:
Runtime error 2465
MS Access can't find the field 'tbl_Type_sub' referred to in your
expression. ( on line ** )

I also tried the following code:
If Me.combo1.Value = "Standard Procedures" Then
Me.frm_Type_sub .FormRecordSour ce = "tbl_StdProc_su b" ' **

Error Message:
Compile error: method or data member not found. (refers to line **)

any suggestions? I double checked to make sure the form names were
correct, and that the code matches. On the first two codes, it gave
the error of not finding field 'frm_Type_sub' but it should be finding
a form, not a field.

thanks!

Do all of the tables have the same field names? Lets say Table1 has ID,
Descriptiuon and table2 has ID, Desc. You built the form on Table1
(description). So what is Desc in Table2 in the form?

Your could use queries perhaps. In the above example, you could have a
query something like
Select ID, Desc as Description From Table2
Now there is a Description column. You'd use the query there.
Nov 13 '05 #5
Stu wrote:
I changed my code to your suggestion, but I get the following message:

If Me.combo1.Value = "Standard Procedures" Then
Me("frm_Type_su b").Form.Record Source = "tbl_StdProc_su b" ' **

and

If Me.combo1.Value = "Standard Procedures" Then
Forms!frm_Type! frm_Type_sub.Fo rm.RecordSource = "tbl_stdProc_su b"
' **

but on both I got the message:
Runtime error 2465
MS Access can't find the field 'tbl_Type_sub' referred to in your
expression. ( on line ** )

I also tried the following code:
If Me.combo1.Value = "Standard Procedures" Then
Me.frm_Type_sub .FormRecordSour ce = "tbl_StdProc_su b" ' **

Error Message:
Compile error: method or data member not found. (refers to line **)

any suggestions? I double checked to make sure the form names were
correct, and that the code matches. On the first two codes, it gave
the error of not finding field 'frm_Type_sub' but it should be finding
a form, not a field.

thanks!

Do all of the tables have the same field names? Lets say Table1 has ID,
Descriptiuon and table2 has ID, Desc. You built the form on Table1
(description). So what is Desc in Table2 in the form?

Your could use queries perhaps. In the above example, you could have a
query something like
Select ID, Desc as Description From Table2
Now there is a Description column. You'd use the query there.
Nov 13 '05 #6
Stu wrote:
Hi,
I have a combobox who's values change the recordsource of the form.
Within this form, there is a subform, whos records also need to change
pending the value in the combobox. I am able to get the main forms
values to change, but not the subform. I've only been using Access 97
for about a month now, so it might be fairly simple. Here is my code:


Maybe I missed something in your post but a record change in the main form would be
reflected in the subform if there is proper linkage between them in the properties of the
SubFormControl - the control on the main form that "holds" the (subform) form.

That's one of the powers of subforms.

As for setting focus from the main to the sub I've found its usually a two-step process.
Set focus to the subform control on the main form and then to a control within the form
contained in the subform control:

Me!sfrmCtrl1.Se tFocus
Me!sfrmCtrl1.Fo rm!controlNameH ereFromSubForm. SetFocus

--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #7
Stu wrote:
Hi,
I have a combobox who's values change the recordsource of the form.
Within this form, there is a subform, whos records also need to change
pending the value in the combobox. I am able to get the main forms
values to change, but not the subform. I've only been using Access 97
for about a month now, so it might be fairly simple. Here is my code:


Maybe I missed something in your post but a record change in the main form would be
reflected in the subform if there is proper linkage between them in the properties of the
SubFormControl - the control on the main form that "holds" the (subform) form.

That's one of the powers of subforms.

As for setting focus from the main to the sub I've found its usually a two-step process.
Set focus to the subform control on the main form and then to a control within the form
contained in the subform control:

Me!sfrmCtrl1.Se tFocus
Me!sfrmCtrl1.Fo rm!controlNameH ereFromSubForm. SetFocus

--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
4549
by: Mark | last post by:
Hi, At the top of my php file I have got :- <body onblur="self.focus();"> so when I click off onto another window, my window comes back up in front which is perfect. The problem however, is that when I try to type into my form boxes, the key transfers are all being lost (i.e. keyboard is disabled)!
17
3866
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a record to the subform (based on the value of the combo box) and requeries the subform control. I want the focus to return to the combo box on the main form when it's done, but I can't get it to do so if the user enters a value and presses Enter...
5
10127
by: Petec | last post by:
Is there a way to prevent a form from getting focus? Thanks! - Pete
1
5056
by: cider123 | last post by:
I've tried working with the SelectedIndices and Items.Selected attributes to get the problem to go away, but not having any luck. Questions I have are: 1) How do you move (using code) the focus Rectangle when your Selected Index changes ? 2) If there are no selected rows, can that focus rectangle be removed? 3) What other quirks exist in this simple example I might need to code for ?
3
6140
by: Greg | last post by:
The LostFocus event of datagrids is fired when the focus is added to a cell. How do you go about detecting it when the control as a whole has lost focus to another control? Slightly confused by this! Greg.
2
5403
by: Sid Price | last post by:
Is there a way of stopping a form getting focus in VB.NET. The scenario I have is a main form and a form used for display only. There are no user controls on the display form and it does not ever need to have the focus. When the displays on the form are updated it appears to get the focus. I would like to prevent this because if the user operates any hot-keys (thinking the main form still has focus) these keys will fail. I have tried...
6
2814
by: Gerhard Heemskerk | last post by:
Hello, I have a button on the main form and the follwing code when you click on it. Though the last record is the sub form (datasheet view) is shown, the focus remains on the button last_transaction on the main form. I tried to get the focus on the sub form form_transaction.setfocus but i get an error 'the expression contains an invalid methode'. When I search for a solution everyone states that the above statement should work. But the...
3
4252
by: jan.loucka | last post by:
Hi, I looked around for this specific problem but could not find any answer - there's few things in VB but still nothing exactly like this so I'd appreciate any help. We're writing C# WinForm application that need to "silently" use another app (called MapInfo) within itself - the intention is to use this app (which is quite sophisticated mapping application) and add some other extra functionality to it. We have a dll so we can run the...
3
3153
by: Johnny Jörgensen | last post by:
I've a form that opens a tool window. The problem is that when the tool window is opened, the main form itself passes focus to the toolwindow. What I want and need is a toolwindow that works like a control with tabstop=false, i.e. it doesn't get focus when the window is opened, but focus is retained at the main form. And when you click a button on the toolwindow, it processes the click event and returns focus to the main form. Is that...
5
3344
by: oscWork | last post by:
Does anyone know of any way to switch focus between a main form and a child form without the usual flickering you get while changing focus between windows? This works fine if the main form is an MDI container and the child form is within that container, but MDI is not appropriate for this application. I would like to be able to interact with a form without losing focus on the main form. Obvious workarounds such as setting focus on the main...
0
9685
marktang
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...
0
9535
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
10465
Oralloy
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...
0
10242
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
10200
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
9061
agi2029
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...
1
7558
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...
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
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.