Tab Control Help Please

G

Guest

Hi

I have a form (say Main Form) where the record source is referring to a Risk
table with a primary key of RiskRefID

Below this form is 3 tab controls where I have several subforms on each tab
where the master/child link to RiskRefID


What I want is when I create on Add New Record, the mouse cursor should goes
back to the Main Form where I completed certain field on this form before a
record can be created, then when pressing the tab ke, the mouse should move
to the first field on Tab 0 not Tab 2.

The problem is when I click on create new record on the main form, the mouse
move to a field on the third tab control ie tab 2.

On the last field on the Main Form, I have wrote a code on the Exit event

docmd.gotocontrol "FirstSubFormName" (this is the first subform on tab 0)
docmd.gotocontrol "FirstControlName"

Unfortunately the above code only works on current record. but does not work
when create new record

Could someone please help.

Many Thanks
Hong
 
R

Rick Brandt

Mail said:
Hi

I have a form (say Main Form) where the record source is referring to
a Risk table with a primary key of RiskRefID

Below this form is 3 tab controls where I have several subforms on
each tab where the master/child link to RiskRefID


What I want is when I create on Add New Record, the mouse cursor
should goes back to the Main Form where I completed certain field on
this form before a record can be created, then when pressing the tab
ke, the mouse should move to the first field on Tab 0 not Tab 2.

The problem is when I click on create new record on the main form,
the mouse move to a field on the third tab control ie tab 2.

On the last field on the Main Form, I have wrote a code on the Exit
event

docmd.gotocontrol "FirstSubFormName" (this is the first subform on
tab 0) docmd.gotocontrol "FirstControlName"

Unfortunately the above code only works on current record. but does
not work when create new record

Could someone please help.

Many Thanks
Hong

In the Current event of the main form...

If Me.NewRecord Then
(your same code)
End If
 
G

Guest

Hi Rick and Arvin

If I used Rick suggestion, then the cursor does move to the
"firstControlName" of the "FirstSubformControlName". but the problem is when
a new record created in the Main Form, only the new RiskREfID visible but
doesn't mean it was created, without select/enter another field in the Main
Form and the sursor move to the FirstSubForm-FirstControlName for data entry,
the error message "cannot Add or Change record because a related record is
required in the Main Form".

I don't have a clue on how to use Arvin advised on SetFocus.

I would like to rephrase my problems.

what I want do achieve is when the cursor move to the "RiskRefID" to
generate a new ID (Primary key), it will then move to the next control name
for data entry into this field to enable a new record is created.

Then tab to move the cursor to the firstcontrolname of the firstsubform on
Tab0.

For some reason after the cursor jump to the Main Form, the tab control
didn't swith back to tab 0. instead it's still display tab 2. I think this
might cause a problem.

Any help please.

Thanks
 
A

Arvin Meyer [MVP]

In the AfterUpdate event of the first control that you actually add data to,
just add the use the line of code:

Me.txtToGoTo.SetFocus

on the control that you want to set focus to.
 
G

Guest

Hi Arvin, it doesn't work,

On the Main Form I have the below code: Data Entry is enabled

Private Sub Form_Current()
If Me.NewRecord Then
Me.RiskRefID.SetFocus ' primary key
End If
End Sub

on the Main from there are a few data entry field where I only make the
RiskRefID and RiskStatus visible for data entry. RiskRefID is the primary key
and RiskStatus is Required.
on the RiskStatus I have the below code.

Private Sub RiskStatus_Exit(Cancel As Integer)
On Error Resume Next
If IsNull(Me.RiskStatus.Value) Then
MsgBox ("Please select Risk Status")
Me.RiskStatus.SetFocus

End If

DoCmd.GoToControl "RSF011_Titles"
DoCmd.GoToControl "Title"


On Error GoTo 0
End Sub


When I open the form for data entry, a new RiskRefID is generated. click on
tab will take me to the RiskStatus, without typing anything in the
RiskStatus, the error message pop up "Please Select Risk Status".

Click on OK, the cursur jump to the "Title" control name on the
"RSF11_RiskTitle" subform which is on tab control no. 0.

Without select the RiskStatus, then there is no record is created on the
Main Form. So I HAVE to use the mouse to select the RiskStatus. now the
problems occur, the mouse jump straight to "ReportDate" control name on the
"RSF15_Reporting" subform on TabControl No3 . Where it should jump to "Title"
on "RSF_011RiskTitle" subform on TabControl No0

On the "ReportDate" I have a code as below:

Private Sub ReportDate_Exit(Cancel As Integer)


Me.Parent.SetFocus
On Error Resume Next
Me.Parent.RiskRefID.SetFocus

DoCmd.GoToRecord , , acNewRec


On Error GoTo 0
End Sub

Tab one more will take me to the RiskRefID, tab to move to RiskStatus.

Here is another problem, If I select the Risk Status, then the cursor will
jump back to the RiskRefID and generate another new RiskRefID. Tab one more
to move to the RiskStatus and select RiskStatus, the cursor then jump back
the RiskRefID and generate new RiskRefID.

I hope you can follow my writing and would be very appreciate your help on
this.
Thanks
Hong
 
A

Arvin Meyer [MVP]

Oh but it does work. I've tried it on tabs in Access 97, 2002, and 2003. I
suggested the AfterUpdate event of the first control that you actually
physically change. I even tested your code in the form's Current event, and
it worked. Clearly, you have another problem. Try this code in your form's
BeforeUpdate event (this code is untested, watch out for line-wrapping):

Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.RiskStatus & vbNullString) < 1 Then
MsgBox "Please select Risk Status", vbOKOnly, "Missing Data"
Me.RiskStatus.SetFocus
End If
End Sub

Your code allowed an error, allowed empty strings, and used a MsgBox
function instead of a MsgBox statement.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
 
G

Guest

Hi Arvin

I really don't know what the problem is, I have tried every thing that you
suggested but I am still getting the same problems.

I am using access 2003 on Window XP.

Thanks for your help anyway.
 
G

Guest

Hi Arvin

I have emailed you my database yesterday, if you haven't receive it by now
please let me know. Thanks for your help.

Hong
 
G

Guest

Hi Arvin

I have emailed you my trouble database, if you haven't receive it please let
me know. Thanks for your help.

Hong
 
R

RHutcheson via AccessMonster.com

Hong

To select a particular tab on a tabbed control, set the value of the tab
control to the value of the page you want. Let's say that you tabbed control
is named TabCtrl100. TabCtrl100=0 will take you to the first tab,
TabCtrl100=3 will take you to the 4th tab and so on. Then you can set your
focus. Does this help?

RHutcheson
 
G

Guest

Hi Arvin

I will try to resend it to you again.

To RHutcheson

My tab control is already in tab order, ie tab index 0 to tab index 2.

The problem won't occur until I create a new record. Other than that, it
works OK when tab on the current records.
 

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