Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Switch Focus

Posted on 2013-01-13
6
Medium Priority
?
252 Views
Last Modified: 2013-01-22
I have the focus on a form locked onto a graph and do not seem to be able to move it to any other field on the form via vba.

Very strange!

Any help welcome.
0
Comment
Question by:SweetingA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 29

Accepted Solution

by:
IrogSinta earned 1500 total points
ID: 38772724
How are you trying to switch focus? Have you tried something like:
Me.NameOfTextbox.SetFocus

If so, you need to provide more information.
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38772802
With the focus on a graph, you may have to us the parent.  I've not tried that before, but depending on where the code is that is executing this, you may need to try something like:

me.parent.setfocus

or possibly

Forms!yourFormName.Form.setfocus

or

Forms!yourFormName.Form.SomeControlName.Setfocus
0
 

Author Comment

by:SweetingA
ID: 38772938
I have tried....

Me.txtboxname.SetFocus - no luck but no error
Forms!myform.txtboxname.SetFocus - no luck but no error
Forms!myform.Form.txtboxname.SetFocus - no luck but no error
Me.Parent.SetFocus - no luck, error - invalid reference to the parent property

Regards
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 29

Expert Comment

by:IrogSinta
ID: 38772950
On what event do you have your code? Is txtboxname the actual name of the textbox control?
0
 

Author Comment

by:SweetingA
ID: 38772992
There is a lot of code running off the back of an after update event, please see code below....

You will have to excuse my clumsy programming as i am no access programmer.

The problem started when i wanted to display a graph, to get the graph to display i needed to double click it so i simulated the mouse click.  When i do that it works but it leaves the graph data table on show - to get rid of that i need to click into any other box which is why i was trying to change the focus to a text box and click on it.

Private Sub Measure_AfterUpdate()
    Dim a As String
    Dim b As String
    Dim c As String
    Dim d As String
    Dim e As String
    Me.Unit.Requery
    Me.[Sort Criteria] = Me.Year & Me.Period & Me.Measure
    Me.[Sort Criteria 2] = Me.Year & Me.Measure
    Me.[Sort Criteria 3] = Me.Year - 1 & Me.Period & Me.Measure
    a = DLookup("[Unit]", "tbl_PDM_TargetProjects", "[Measure]=Forms!frm_PDM_Results.Measure")
    b = DCount("[Sort Criteria]", "tbl_PDM_Results", "[Sort Criteria] = Forms!frm_PDM_Results.[Sort Criteria]")
    c = DCount("[Result]", "tbl_PDM_Results", "[Sort Criteria]=Forms!frm_PDM_Results.[Sort Criteria 3]")
    If c = 1 Then
        d = DLookup("[Result]", "tbl_PDM_Results", "[Sort Criteria]=Forms!frm_PDM_Results.[Sort Criteria 3]")
        Me.PYR = d
        strSQL = "UPDATE tbl_PDM_Results" & " SET tbl_PDM_Results.[Previous Year Result] = " & d & " WHERE [Sort Criteria] = Forms!frm_PDM_Results.[Sort Criteria 3]"
        With DoCmd
            .SetWarnings False
            .RunSQL strSQL
            .SetWarnings True
        End With
    End If
    If b = 0 Then
        If IsNull(Measure) Then
            MsgBox ("Enter Measure")
            Me.Result.Locked = True
            Me.Measure.SetFocus
        Else:
            Me.Unit = a
            Me.Result.Locked = False
            CurrentDb.Execute "delete * from tbl_PDM_Results WHERE [Result] is NULL"
            Me.frm_PDM_Results_subform.Visible = True
            Me.SubformLabel.Visible = True
            Me.Graph1.Visible = True
            Me.Graph1.SetFocus
            Call LeftClick
            Call LeftClick
            Me.Result.SetFocus
            Call LeftClick
        End If
    Else:
        e = MsgBox("Record exists, do you want to update an existing record?", vbYesNo)
        If e = vbNo Then
            Me.Year = Null
            Me.Period = Null
            Me.Project_Category = Null
            Me.Measure = Null
            Me.Unit = Null
            Me.Sort_Criteria = Null
            Me.[Sort Criteria] = Null
            Me.[Sort Criteria 2] = Null
            Me.[Sort Criteria 3] = Null
            Me.Year.SetFocus
        ElseIf (e = vbYes) Then
            With Me.RecordsetClone
            .FindFirst "[Sort Criteria]='" & Me.[Sort Criteria] & "'"
            If Not .NoMatch Then
                Me.Bookmark = .Bookmark
            Else
                MsgBox "Record not found"
            End If
            End With
            CurrentDb.Execute "delete * from tbl_PDM_Results WHERE [Result] is NULL"
            Me.frm_PDM_Results_subform.Visible = True
            Me.SubformLabel.Visible = True
            Me.Graph1.Visible = True
            Me.Graph1.SetFocus
            Call LeftClick
            Call LeftClick
            Me.Result.SetFocus
            Call LeftClick
        End If
    End If
End Sub

Thanks
0
 

Author Closing Comment

by:SweetingA
ID: 38807804
Simple but correct, other issues at play here, focus seems to be switching to item directly under position of yes/no buttons on message box
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question