• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

How do set focus in tabcontrol

Hi: Can any one please tell me how do i set focus in tab control. I try it but no error and dont work.

Me.Child17.Form.[Service].setfocus

Thanks.
0
mustish1
Asked:
mustish1
4 Solutions
 
dannywarehamCommented:
http://www.mvps.org/access/forms/frm0025.htm

If you are "on" the child subform, then it is simply:

Me.[service].setfocus

If you are on the mainform, you have teh syntax correct
0
 
mustish1Author Commented:
If I am in the main form

    If IsNull(Me.Child17.Form.[Service]) = True Or Me.Child17.Form.[Service] = "" Then
       MsgBox "Service Required"
       Me.Child17.Form.[Service].SetFocus
       Exit Sub
    End If
0
 
mustish1Author Commented:
Sorry
If Me.TabCtl12.Pages(Me.TabCtl12.Value).Name = "Add" Then
    If IsNull(Me.Child17.Form.[Service]) = True Or Me.Child17.Form.[Service] = "" Then
       MsgBox "Service Required"
       Me.Child17.Form.[Service].SetFocus
       Exit Sub
    End If
end if
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
dannywarehamCommented:
?? That looks fine to me...  

Try this:

STOP
If Me.TabCtl12.Pages(Me.TabCtl12.Value).Name = "Add" Then
    If IsNull(Me.Child17.Form.[Service]) Or Me.Child17.Form.[Service] = "" Then
    Me.Child17.Form.[Service].SetFocus      
    MsgBox "Service Required"
    End If
End if


When you click your button, you will be sent to the code screen.
Use F8 to step through the code.

It makes it easier to spot errors.

Hovering your mouse over the variables or controls (like [Service]) will show you what value they're holding.
0
 
jefftwilleyCommented:
Hey M,
Here's a roundabout way

Me.Admin.SetFocus   '<-------------Admin is the NAME of the tab
Me.frm_Export.SetFocus   '<--------this is my subform
DoCmd.GoToControl "ExpList"   '<----this is my control

J
0
 
Leigh PurvisDatabase DeveloperCommented:
Jeff pretty much has it - though I'd do it differently (just because I'm not a huge fan of GoToControl... or GotoRecord for that matter).

It's an known issue that you can't necessarily set focus to a control in a subform in one fell swoop.
You can be more assured of it working by first setting focus to the subform control and then setting focus to the subform's form control.

With Me.Child17
    .SetFocus                               'Set's focus to a control - which just happens to be a subform control.
    .Form.[Service].SetFocus         'Sets focus to the desired control
End With

Very much the same as Jeff's - just with some reassurance that this can happen and working around it is OK. :-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now