tab order

G

Guest

I have a form with 2 subforms' Bills and Payments. When bills are logged the
Bills subform is completed populated and the Payments subform is partially
populated. I want to be able to tab through the last field of the Payments
subform and return to the first field of a new record in the Bills subform.
The reason I have a payments table is that I may have multiple installments
to pay the bill. Thanks in advance.
 
K

Ken Snell \(MVP\)

First, will you *always* want to go to a new record in the Bills subform
when you finish entering the data on the Payments subform? If not, you
shouldn't program the form to do that all the time. You could put a button
on the Payments subform that, when clicked, would take you to a new record
on Bills subform:

Private Sub ButtonName_Click()
Me.Parent.NameOfSubformControlHoldingBillsSubform.SetFocus
Me.Parent.NameOfSubformControlHoldingBillsSubform.Form.NameOfControlInBillssubformSetFocus
Me.Parent.NameOfSubformControlHoldingBillsSubform.Form.Recordset.AddNew
End Sub

Otherwise, if you always want to make the move, the code above can be put in
the Exit event of the last control of the Payments subform(assuming that
there is only one record in that subform).

If you have multiple records in the Payments subform, things get complicated
to run automatic code, as you'd need to test if you're on the last record
and make the move only if it's the last record.
 
J

John Vinson

I have a form with 2 subforms' Bills and Payments. When bills are logged the
Bills subform is completed populated and the Payments subform is partially
populated. I want to be able to tab through the last field of the Payments
subform and return to the first field of a new record in the Bills subform.
The reason I have a payments table is that I may have multiple installments
to pay the bill. Thanks in advance.

Ummm...

If you want to allow multiple records in the Payments subform, why
would you want to make it hard to get to the new record on the subform
to enter one? That would be the effect!

If you *do* want to do this, put a textbox on the Payments subform
last in the tab order. It must be vixible, but it can be hidden behind
another control so the user can't mouse into it. In its GotFocus event
put code like

Private Sub txtRelay_GotFocus()
Parent.SetFocus
Parent!Bills.SetFocus ' set focus to the other subform
DoCmd.GoToRecord acForm, "[Forms]![formname]![Bills]", acNewRecord
Parent!Bills.Form!txtFirstControl.SetFocus ' then to a control on it


John W. Vinson[MVP]
 
G

Guest

I will always want to go to a new record in the Bills subform when logging
tax bills.

I didn't understand your code, but here is my attempt to use it.

subform: fsubTax_Bills; first control on form: Company_ID
subform: fsubPayments; last control on form: Tax_Install_Paid_Date

Private sub Tax_Install_Paid_Date_Exit
Me.Parent.Company_ID.SetFocus
Me.Parent.Company_ID.fsubTax_Bills.Company_ID
Me.Parent.Company_ID.fsubTax_Bills.Recordset.AddNew
End Sub

Thanks for your help
 
K

Ken Snell \(MVP\)

Try this:

Private sub Tax_Install_Paid_Date_Exit
Me.Parent.fsubTax_Bills.SetFocus
Me.Parent.fsubTax_Bills.Form.Company_ID.SetFocus
Me.Parent.fsubTax_Bills.Form.Recordset.AddNew
Me.Parent.fsubTax_Bills.Form.Company_ID.SetFocus
End Sub
 
G

Guest

Ken,
I tried it but got a Run-time error '2465', Application defined or
object-defined error. I double checked my typing and the subform names and
control names but everything looked okay.
 
K

Ken Snell \(MVP\)

On which line of code do you get the error?

Might be necessary to move focus to main form first:

Private sub Tax_Install_Paid_Date_Exit
Me.Parent.NameOfAControlOnMainForm.SetFocus
Me.Parent.fsubTax_Bills.SetFocus
Me.Parent.fsubTax_Bills.Form.Company_ID.SetFocus
Me.Parent.fsubTax_Bills.Form.Recordset.AddNew
Me.Parent.fsubTax_Bills.Form.Company_ID.SetFocus
End Sub
 
G

Guest

Yes, I wrote the first line as:
Me.Parent.frmJurisdictions.cboJurisdiction.SetFocus
I tried it with the same results and the debugger highlighted the first line
of code. I then deleted the frmJurisdictions out of the code and tried
again, same results.
 
G

Guest

Thought this could be important. I am working in Access 2003 but in Access
2000 format.
Thanks
 
K

Ken Snell \(MVP\)

Two things come to mind:

(1) The code is not running in a subform (no Parent property). However,
based on what you've posted, this seems unlikely. However, the error is
consistent with this problem.

(2) There is an error occurring in another event within the subform that
causes that event to be terminated, thus your code isn't able to run. But
that often yields an error of "you cannot move focus to that control at this
time" or some similar error.

Can cboJurisdiction receive the focus on the main form?

Perhaps try John Vinson's suggestion of putting focus on the main form
itself (which will cause focus to go to a control that can receive the
focus):

Private sub Tax_Install_Paid_Date_Exit(Cancel As Integer)
Me.Parent.SetFocus
Me.Parent.fsubTax_Bills.SetFocus
Me.Parent.fsubTax_Bills.Form.Company_ID.SetFocus
Me.Parent.fsubTax_Bills.Form.Recordset.AddNew
Me.Parent.fsubTax_Bills.Form.Company_ID.SetFocus
End Sub


What other code do you have in the fsubPayments subform object?
 
G

Guest

I tried the code you sent, now I get run-time error "2449" There is a invalid
method in an expression. The debugger still highlights the first line of
code.

There is no other code in the subform fsubPayments.
cboJurisdiction can receive the focus, but cboState would probably be better.

--
cbishop


Ken Snell (MVP) said:
Two things come to mind:

(1) The code is not running in a subform (no Parent property). However,
based on what you've posted, this seems unlikely. However, the error is
consistent with this problem.

(2) There is an error occurring in another event within the subform that
causes that event to be terminated, thus your code isn't able to run. But
that often yields an error of "you cannot move focus to that control at this
time" or some similar error.

Can cboJurisdiction receive the focus on the main form?

Perhaps try John Vinson's suggestion of putting focus on the main form
itself (which will cause focus to go to a control that can receive the
focus):

Private sub Tax_Install_Paid_Date_Exit(Cancel As Integer)
Me.Parent.SetFocus
Me.Parent.fsubTax_Bills.SetFocus
Me.Parent.fsubTax_Bills.Form.Company_ID.SetFocus
Me.Parent.fsubTax_Bills.Form.Recordset.AddNew
Me.Parent.fsubTax_Bills.Form.Company_ID.SetFocus
End Sub


What other code do you have in the fsubPayments subform object?
 
K

Ken Snell \(MVP\)

If you're willing to send me a small version of the database in a zip file,
I'll take a look at it and see what's happening. You can get my email
address by looking at the ReplyTo email address (which is munged) and
removing the words " this is not real " from the address; what's left is my
email address.

--

Ken Snell
<MS ACCESS MVP>

Cary Bishop said:
I tried the code you sent, now I get run-time error "2449" There is a
invalid
method in an expression. The debugger still highlights the first line of
code.

There is no other code in the subform fsubPayments.
cboJurisdiction can receive the focus, but cboState would probably be
better.
 
G

Guest

Ken, I'm new to this. What in munged? I can't find a replyto email address.
I would be happy to send a small version of the database. Please define
small. The database is now 1548 KB unzipped.
 
K

Ken Snell \(MVP\)

Munged means that the real address has been "modified" so that the apparent
address is not real.

Here's my reply-to address (you can see this if you look at the Message
Source of the post, or if you click "Reply To" as the option instead of
"reply to post":
(e-mail address removed)

A 1.6MB file is fine. Be sure to include clear instructions for how to
reproduce what you're seeing, including identifying the specific form, etc.
(Note: I am going away for a few days starting in 24 hours, so please email
it as soon as possible.)
 
K

Ken Snell \(MVP\)

I've looked at your database. What you have is three subforms, embedded in
each other, within a main form. That is slightly different from your initial
description, but it's not a problem.

The following code is what you want to use for the "Got Focus" event of the
"relay" textbox that you're using in the most deeply nested subform (the
payments subform):

Private Sub txtRelay_GotFocus()
' move focus within subform to the first field in the record
' (this is needed so that you can go back into the subform
' after adding a new "bills" record)
Me.Tax_Bill_Install_Number.SetFocus
' move focus to the CompanyID control in the second subform
' (the parent of the third subform)
Me.Parent.Form!Company_ID.SetFocus
' begin a new record in the "bills" subform
Me.Parent.Form.Recordset.AddNew
' set focus to the first control in the new record (just to be sure
' that the focus is where you want it to be)
Me.Parent.Form!Company_ID.SetFocus
End Sub

--

Ken Snell
<MS ACCESS MVP>


Cary Bishop said:
I tried the code you sent, now I get run-time error "2449" There is a
invalid
method in an expression. The debugger still highlights the first line of
code.

There is no other code in the subform fsubPayments.
cboJurisdiction can receive the focus, but cboState would probably be
better.
 
G

Guest

Hi Ken

I have followed your answer to this question and it works ok with mine,ie
when I tab, it move from Main from to Subform1 one then Subform2. I have cut
the last two line and used the below code only on the last text field of
subform1 to move to the first field of subform2.

Private sub Tax_Install_Paid_Date_Exit(Cancel As Integer)
Me.Parent.SetFocus
Me.Parent.fsubTax_Bills.SetFocus
Me.Parent.fsubTax_Bills.Form.Company_ID.SetFocus

My problem is that after I entered data in Subform1 and tab to subform2,
Subform1 become blank. I suspected that it has move to the new data line.

If I change the Cycle in Subform1 to "current record",then the above code
doesn't works. Both my subforms is single forms and I want to show the
record that I last entered on all subform. Could you please help me overcome
this problems.

Thanks
Hong
 

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