473,411 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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_stdProc"
ElseIf Me.combo1.Value = "Policy" Then
Me.RecordSource = "tbl_policy"
ElseIf Me.combo1.Value = "Process Description" Then
Me.RecordSource = "tbl_ProcDesc"
ElseIf Me.combo1.Value = "Program Description" Then
Me.RecordSource = "tbl_ProgDesc"
ElseIf Me.combo1.Value = "Training Program" Then
Me.RecordSource = "tbl_TrainProg"
ElseIf Me.combo1.Value = "Qualification" Then
Me.RecordSource = "tbl_Qual"
ElseIf Me.combo1.Value = "Standard / Specification" Then
Me.RecordSource = "tbl_StdSpec"
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_sub"
ElseIf Me.combo1.Value = "Policy" Then
Me.RecordSource = "tbl_policy_sub"
ElseIf Me.combo1.Value = "Process Description" Then
Me.RecordSource = "tbl_ProcDesc_sub"
ElseIf Me.combo1.Value = "Program Description" Then
Me.RecordSource = "tbl_ProgDesc_sub"
ElseIf Me.combo1.Value = "Training Program" Then
Me.RecordSource = "tbl_TrainProg_sub"
ElseIf Me.combo1.Value = "Qualification" Then
Me.RecordSource = "tbl_Qual_sub"
ElseIf Me.combo1.Value = "Standard / Specification" Then
Me.RecordSource = "tbl_StdSpec_sub"
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 2364
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_stdProc"
ElseIf Me.combo1.Value = "Policy" Then
Me.RecordSource = "tbl_policy"
ElseIf Me.combo1.Value = "Process Description" Then
Me.RecordSource = "tbl_ProcDesc"
ElseIf Me.combo1.Value = "Program Description" Then
Me.RecordSource = "tbl_ProgDesc"
ElseIf Me.combo1.Value = "Training Program" Then
Me.RecordSource = "tbl_TrainProg"
ElseIf Me.combo1.Value = "Qualification" Then
Me.RecordSource = "tbl_Qual"
ElseIf Me.combo1.Value = "Standard / Specification" Then
Me.RecordSource = "tbl_StdSpec"
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_sub"
ElseIf Me.combo1.Value = "Policy" Then
Me.RecordSource = "tbl_policy_sub"
ElseIf Me.combo1.Value = "Process Description" Then
Me.RecordSource = "tbl_ProcDesc_sub"
ElseIf Me.combo1.Value = "Program Description" Then
Me.RecordSource = "tbl_ProgDesc_sub"
ElseIf Me.combo1.Value = "Training Program" Then
Me.RecordSource = "tbl_TrainProg_sub"
ElseIf Me.combo1.Value = "Qualification" Then
Me.RecordSource = "tbl_Qual_sub"
ElseIf Me.combo1.Value = "Standard / Specification" Then
Me.RecordSource = "tbl_StdSpec_sub"
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.Recordsource = "tbl_stdProc_sub"
elseif Me.combo1.Value = "Policy" Then
Me("SubFormName").Form.Recordsource = "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_sub").Form.RecordSource = "tbl_StdProc_sub" ' **

and

If Me.combo1.Value = "Standard Procedures" Then
Forms!frm_Type!frm_Type_sub.Form.RecordSource = "tbl_stdProc_sub"
' **

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.FormRecordSource = "tbl_StdProc_sub" ' **

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_sub").Form.RecordSource = "tbl_StdProc_sub" ' **

and

If Me.combo1.Value = "Standard Procedures" Then
Forms!frm_Type!frm_Type_sub.Form.RecordSource = "tbl_stdProc_sub"
' **

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.FormRecordSource = "tbl_StdProc_sub" ' **

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_sub").Form.RecordSource = "tbl_StdProc_sub" ' **

and

If Me.combo1.Value = "Standard Procedures" Then
Forms!frm_Type!frm_Type_sub.Form.RecordSource = "tbl_stdProc_sub"
' **

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.FormRecordSource = "tbl_StdProc_sub" ' **

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_sub").Form.RecordSource = "tbl_StdProc_sub" ' **

and

If Me.combo1.Value = "Standard Procedures" Then
Forms!frm_Type!frm_Type_sub.Form.RecordSource = "tbl_stdProc_sub"
' **

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.FormRecordSource = "tbl_StdProc_sub" ' **

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.SetFocus
Me!sfrmCtrl1.Form!controlNameHereFromSubForm.SetFo cus

--
'---------------
'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.SetFocus
Me!sfrmCtrl1.Form!controlNameHereFromSubForm.SetFo cus

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

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

Similar topics

14
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...
17
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...
5
by: Petec | last post by:
Is there a way to prevent a form from getting focus? Thanks! - Pete
1
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...
3
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...
2
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...
6
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...
3
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...
3
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...
5
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.