Property to decide who has focus

G

Guest

Is there a property or something that can tell you what has focus?
I am going into a subform and on entry, giving focus to a list of
selections, and then returning to the subform. But I need to know what field
should have focus upon returning. I am looking for something that says:

Subform_OnEnter()
hasfocus = thisfieldhasthefocus
Bunch of calcualtions that reset the focus
thisfieldhasthefocus.setfocus
Endsub

Thanks
 
?

=?iso-8859-1?Q?J=F6rg_Ackermann?=

Hi,

Lee schreibselte:
Is there a property or something that can tell you what has focus?
I am going into a subform and on entry, giving focus to a list of
selections, and then returning to the subform. But I need to know
what field should have focus upon returning. I am looking for
something that says:

Subform_OnEnter()
hasfocus = thisfieldhasthefocus
Bunch of calcualtions that reset the focus
thisfieldhasthefocus.setfocus
Endsub

Try

hasfocus = screen.activecontrol.name

Acki
 
G

Guest

For some reason, it does not have the name property, I looked into that. It
may be because I am entering in a subform and firing off the event at that
time, so there may be no focus at the point of entry?
 
M

Marshall Barton

Lee said:
Is there a property or something that can tell you what has focus?
I am going into a subform and on entry, giving focus to a list of
selections, and then returning to the subform. But I need to know what field
should have focus upon returning. I am looking for something that says:

Subform_OnEnter()
hasfocus = thisfieldhasthefocus
Bunch of calcualtions that reset the focus
thisfieldhasthefocus.setfocus
Endsub


There's a problem with this question. When the user does
something to move to the subform, the containing subform
control has the focus. However, you could use
Screen.PreviousControl to do what you asked.

Another potential problem is that you probably don't need to
do what you asked. There is rarely a need to set the focus
to any control just to do some calculations. Are you a VB
programmer that has been habituated to the Text property?
If so, don't do that. In Access you want to use the Value
property, which does not need to have the focus.
 
G

Guest

Basically what I am doing is ensuring a subform has a value. I have a main
form, called Expense request with a unique request number. This request
number is tied into a subform called vendor quotes. The issue arises when a
user can enter in the vendor information first, and then enter information
into the request. The request number does not populate until a value is
entered in any box on the main form, and then focus is taken away. I just
need to ensure the req number is populated before accepting information in
the vendor field. So I check if the Req number is NULL. If it is, I set
focus to a field in the main form, and change a value by setting it equal to
itself again. Then I want to set focus back to the subform. That way I
guarantee the information from teh vendor (There will be 3 of them) is tied
into to request for later viewing.
 
K

Kurt Wimberger via AccessMonster.com

How I do that same action on a form with subform is this: (In VBA - assue
we are running code from the main form)

'--- Test to see if the main form has a value.
If ("" & Me.txtSomeField.Value) = "" Then
'----- No value in main form.
MsgBox "Error - blah blah blah..."
Else
'----- Main form has data. Copy it to sub form.
Forms("mainForm").subFormName.txtSomeOtherField.Value =
Me.txtSomeField.Value
End If
 
T

tina

i can think of two ways to handle your issue.

1) put the following code in the subform control's Enter event procedure, as

Me!SubformControl.Locked = IsNull(Me!PrimaryKeyField)

if the current record in the main form has no primary key value, then the
subform control is locked, and vice versa.

2) if you want to allow your user to add vendor information before entering
request information, put the following code in the *subform* module's
AfterInsert event, as

With Me.Parent
If .NewRecord Then
.SomeField = 1
.Dirty = False
.SomeField = Null
.Dirty = False
End If
End With

as soon as the user begins adding a new record in the subform, the event
fires and checks the main form. if no data was entered in the main form
record, then NewRecord = True. at that point, the code enters a "dummy"
value (in whatever field you want) and saves the record, generating the
primary key, and then erases the dummy value and saves the record again. the
primary key value immediately and automatically transfers to the currect
subform record, so it's there when the user completes and saves the subform
record.

note: if you're populating the primary key on the main form
programmatically, rather than using an Autonumber, just run your "create
primary key" code instead of (or in addition to) populating a field with
dummy data.

hth
 
M

Marshall Barton

Lee said:
Basically what I am doing is ensuring a subform has a value. I have a main
form, called Expense request with a unique request number. This request
number is tied into a subform called vendor quotes. The issue arises when a
user can enter in the vendor information first, and then enter information
into the request. The request number does not populate until a value is
entered in any box on the main form, and then focus is taken away. I just
need to ensure the req number is populated before accepting information in
the vendor field. So I check if the Req number is NULL. If it is, I set
focus to a field in the main form, and change a value by setting it equal to
itself again. Then I want to set focus back to the subform. That way I
guarantee the information from teh vendor (There will be 3 of them) is tied
into to request for later viewing.


My preferred way to deal with this kind of thing is to avoid
the problem by making the subform control invisible (or
disabled). Then I use the main form's Dirty event to make
the subform control visible (or enabled).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top