473,416 Members | 1,867 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,416 software developers and data experts.

HELP - Using GoToControl in subforms

Hi

I have created a form which contains a subform.

To cut a long story short, I have created a macro that moves the focus to
the subform (GoToControl) and sets a value (SetValue) in the field on the
subform that recieves the focus.

The basic steps of the macro are:

GotoControl [subform]
GoToRecord - First
SetValue

This macro works perfectly when I run it from the Tools-Macro-Run Macro
menu. ie. The value I want setting, is set on the first record in the
subform.

But when I trigger the macro by entering a value in the main form
(AfterUpdate), the GoToRecord - First command moves the focus to the first
record in my main form.

Can anyone explain why the macro works perfectly from the tools menu but not
when I trigger it by the After Update event?

I have run the macro through in single steps and tried everything else I can
think of but I think I am defeated by this one (Which sounds so simple).

Can anyone help?

Thanx


Dec 8 '05 #1
4 7690
Setting the focus to a control on a subform is a two step process.

1) Set the focus to the subform control on the main form
2) Set the focus to the control on the subform

You should be able to set the value without setting the focus to the
control. The syntax to refer to a control on the subform is

Forms!NameOfMainForm!NameOfSubformControl.Form!Nam eOfControlOnSubform

However, this will place the value in the current record on the subform, not
the first record.

I tried playing with a macro to move the focus to a control on the subform,
but didn't get it right. It is doable in VBA using the method mentioned
above. You can also skip going to the control and just tell the subform to
move to the first record and assign a value to the control.

Example:
Me.NameOfSubformControl.Form.Recordset.MoveFirst
Me.NameOfSubformControl.Form.NameOfControlOnSubfor m = <your value>

--
Wayne Morgan
MS Access MVP
"Elaine" <el**********@virgin.net> wrote in message
news:qc*****************@newsfe7-gui.ntli.net...
Hi

I have created a form which contains a subform.

To cut a long story short, I have created a macro that moves the focus to
the subform (GoToControl) and sets a value (SetValue) in the field on the
subform that recieves the focus.

The basic steps of the macro are:

GotoControl [subform]
GoToRecord - First
SetValue

This macro works perfectly when I run it from the Tools-Macro-Run Macro
menu. ie. The value I want setting, is set on the first record in the
subform.

But when I trigger the macro by entering a value in the main form
(AfterUpdate), the GoToRecord - First command moves the focus to the first
record in my main form.

Can anyone explain why the macro works perfectly from the tools menu but
not when I trigger it by the After Update event?

I have run the macro through in single steps and tried everything else I
can think of but I think I am defeated by this one (Which sounds so
simple).

Can anyone help?

Thanx

Dec 8 '05 #2
"Wayne Morgan" <co***************************@hotmail.com> wrote in
news:N_*******************@newssvr11.news.prodigy. com:
Example:
Me.NameOfSubformControl.Form.Recordset.MoveFirst
Me.NameOfSubformControl.Form.NameOfControlOnSubfor m = <your value>


I'm confused by this. Is it not possible for navigation in the
Recordset to cause the same kinds of problems that we refer to as
the Bookmark bug, which involved the RecordsetClone, which previous
to A2K was the only recordset that was usable for navigation? That
is, shouldn't you check for Me!NameOfSubformControl.Form.Dirty and
set it to False before moving the recordset pointer?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Dec 9 '05 #3
David,

Checking for a dirty record first and saving it if it is (i.e. setting Dirty
to False) is probably a good idea and definitely won't hurt anything. I
haven't personally run across the bug, although I've heard about it.

--
Wayne Morgan
MS Access MVP
"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@216.196. 97.142...
"Wayne Morgan" <co***************************@hotmail.com> wrote in
news:N_*******************@newssvr11.news.prodigy. com:
Example:
Me.NameOfSubformControl.Form.Recordset.MoveFirst
Me.NameOfSubformControl.Form.NameOfControlOnSubfor m = <your value>


I'm confused by this. Is it not possible for navigation in the
Recordset to cause the same kinds of problems that we refer to as
the Bookmark bug, which involved the RecordsetClone, which previous
to A2K was the only recordset that was usable for navigation? That
is, shouldn't you check for Me!NameOfSubformControl.Form.Dirty and
set it to False before moving the recordset pointer?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc

Dec 9 '05 #4
"Wayne Morgan" <co***************************@hotmail.com> wrote in
news:tV*******************@newssvr11.news.prodigy. com:
Checking for a dirty record first and saving it if it is (i.e.
setting Dirty to False) is probably a good idea and definitely
won't hurt anything. I haven't personally run across the bug,
although I've heard about it.


I think that anytime you know that an action that you're taking is
going to depart a record, it's a good idea to explicitly save the
record. This forces all error checking routines to run, whereas it's
clear that in some circumstances (e.g., the bookmark navigation
situation, the form close bug), that just doesn't happen.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Dec 9 '05 #5

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

Similar topics

1
by: JJMM | last post by:
Hi, I have a form (form1) with a large number of subforms inside it (around 20 subforms), There is the possibility of filtering the data using a pop-up form that create/change a query (all the...
2
by: mark | last post by:
I've been working on an Access 2000 database for a couple of weeks now. I took a course in access about a year ago, a crash course, and I learned a ton, but I didn't touch Access for the year since...
2
by: Mike | last post by:
Hi I have been tasked with converting my pulp and paper mills weekly projected and actual contractor hrs excel spreadsheet into a an Access 97 database. So far my design has been to use a...
3
by: radioman | last post by:
Hi all, I would appreciate some help please. I just need pointing in the right direction as I am at a loss. Basically I have a form (frmAddMaster) which displays two subforms "Master Stock...
8
by: newbie | last post by:
hello How can I update more than one tables on the same form? The relationship is one to many from a master table to 3 other related tables. on the form, I have to setvalue for a few...
4
by: MLH | last post by:
HelpBox is a textbox control on a form. When line #254 is processed, the focus is on HelpBox. However, when line #254 executes, the error saying 'can't move focus to ButtonG' is returned. I've...
1
by: El | last post by:
Please help!! I have a form and in it are several subforms. In order for users to move from the main form to the subforms there are tabs on the upper part of the form. I have one field that...
3
by: google | last post by:
I'm developing an application for use within my company in Access 2003. I'm new to '03, the application I did for my former employer was in '97. The two applications have similar functionality...
1
by: dlreich | last post by:
While viewing a form, I use Find (Ctrl-F) to find a new record. In On Current for the form, I use GoToControl to adjust the display of one of the fields in the new record. Is there any way I can...
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
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...
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
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
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.