SweetingA
asked on
Switch Focus
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.
Very strange!
Any help welcome.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have tried....
Me.txtboxname.SetFocus - no luck but no error
Forms!myform.txtboxname.Se tFocus - no luck but no error
Forms!myform.Form.txtboxna me.SetFocu s - no luck but no error
Me.Parent.SetFocus - no luck, error - invalid reference to the parent property
Regards
Me.txtboxname.SetFocus - no luck but no error
Forms!myform.txtboxname.Se
Forms!myform.Form.txtboxna
Me.Parent.SetFocus - no luck, error - invalid reference to the parent property
Regards
On what event do you have your code? Is txtboxname the actual name of the textbox control?
ASKER
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_R esults.Mea sure")
b = DCount("[Sort Criteria]", "tbl_PDM_Results", "[Sort Criteria] = Forms!frm_PDM_Results.[Sor t Criteria]")
c = DCount("[Result]", "tbl_PDM_Results", "[Sort Criteria]=Forms!frm_PDM_Re sults.[Sor t Criteria 3]")
If c = 1 Then
d = DLookup("[Result]", "tbl_PDM_Results", "[Sort Criteria]=Forms!frm_PDM_Re sults.[Sor t 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.[Sor t 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
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_R
b = DCount("[Sort Criteria]", "tbl_PDM_Results", "[Sort Criteria] = Forms!frm_PDM_Results.[Sor
c = DCount("[Result]", "tbl_PDM_Results", "[Sort Criteria]=Forms!frm_PDM_Re
If c = 1 Then
d = DLookup("[Result]", "tbl_PDM_Results", "[Sort Criteria]=Forms!frm_PDM_Re
Me.PYR = d
strSQL = "UPDATE tbl_PDM_Results" & " SET tbl_PDM_Results.[Previous Year Result] = " & d & " WHERE [Sort Criteria] = Forms!frm_PDM_Results.[Sor
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
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
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
ASKER
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
me.parent.setfocus
or possibly
Forms!yourFormName.Form.se
or
Forms!yourFormName.Form.So