Tab index with Tab Control

G

Gator

I have a Main form with a textbox control and a Tab Control below that
contains a subform, in datasheet view, on one of the tabs. I want to enter a
date in the textbox on the Main form and then press either tab or enter and
the focus goes to the subform's first record. What's happening is when I
enter the date on the Main form and press tab or enter, the Main form starts
a new record. I've been trying to set the tab indexes on the form's
properties window. Is it easier to do this in code? How would the code read?
 
R

Ryan

Private Sub DateTextbox_LostFocus()
DoCmd.GoToControl "[Forms]![YourSubformName].[YourFieldName]"
End Sub

A way to prevent going to a new record is to go to the properties of the
form, then to the other tab and changing Cycle to Current Record
 
G

Gator

I get a runtime error 2109----
"There is no field named 'MySubformName.MyFieldName' in the current record.
--
Gator


Ryan said:
Private Sub DateTextbox_LostFocus()
DoCmd.GoToControl "[Forms]![YourSubformName].[YourFieldName]"
End Sub

A way to prevent going to a new record is to go to the properties of the
form, then to the other tab and changing Cycle to Current Record
--
Please remember to mark this as answered if this solves your problem.


Gator said:
I have a Main form with a textbox control and a Tab Control below that
contains a subform, in datasheet view, on one of the tabs. I want to enter a
date in the textbox on the Main form and then press either tab or enter and
the focus goes to the subform's first record. What's happening is when I
enter the date on the Main form and press tab or enter, the Main form starts
a new record. I've been trying to set the tab indexes on the form's
properties window. Is it easier to do this in code? How would the code read?
 
D

Douglas J. Steele

Ryan's information was incorrect.

You cannot refer directly to a form being used as a subform in that manner:
subforms aren't actually in the Forms collection. Instead, you have to refer
to it via the subform control on the parent form.

Assuming that that code is associated with the parent form, you'd use

Me!NameOfSubformControl.Form!NameOfField

If it's somewhere else, you'd use

Forms!NameOfParentForm!NameOfSubformControl.Form!NameOfField

Note that depending on how you added the subform to the parent form, the
name of the subform control may be different than the name of the form being
used as a subform.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Gator said:
I get a runtime error 2109----
"There is no field named 'MySubformName.MyFieldName' in the current
record.
--
Gator


Ryan said:
Private Sub DateTextbox_LostFocus()
DoCmd.GoToControl "[Forms]![YourSubformName].[YourFieldName]"
End Sub

A way to prevent going to a new record is to go to the properties of the
form, then to the other tab and changing Cycle to Current Record
--
Please remember to mark this as answered if this solves your problem.


Gator said:
I have a Main form with a textbox control and a Tab Control below that
contains a subform, in datasheet view, on one of the tabs. I want to
enter a
date in the textbox on the Main form and then press either tab or enter
and
the focus goes to the subform's first record. What's happening is when
I
enter the date on the Main form and press tab or enter, the Main form
starts
a new record. I've been trying to set the tab indexes on the form's
properties window. Is it easier to do this in code? How would the
code read?
 

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

Similar Threads


Top