Setting Focus after error

  • Thread starter Thread starter Nylex
  • Start date Start date
N

Nylex

If they try to enter a record without a selection in the parent form I need
to return them to the main form - I have tried different ways but none work -
this is my current try
Private Sub ModelName_Enter()
Dim StrName As String
Dim i As Integer
Dim Msg As String
StrName = Nz(Me.Parent![VehName])
If StrName = "" Then GoTo 100
GoTo 200
100
Msg = "'" & "' No Vehicle Name is Selected."
Msg = Msg & " - Select Vehicle Name"
i = MsgBox(Msg, vbQuestion + vbYesonly, "Unknown Vehicle...")
Response = acDataErrContinue
Forms!vehicle!VehName.SetFocus
200 Exit Sub
End Sub
When it returns it goes to the field ON THE SUBFORM that it started in - not
the parent form
 
Nylex said:
If they try to enter a record without a selection in the parent form I
need
to return them to the main form - I have tried different ways but none
work -
this is my current try
Private Sub ModelName_Enter()
Dim StrName As String
Dim i As Integer
Dim Msg As String
StrName = Nz(Me.Parent![VehName])
If StrName = "" Then GoTo 100
GoTo 200
100
Msg = "'" & "' No Vehicle Name is Selected."
Msg = Msg & " - Select Vehicle Name"
i = MsgBox(Msg, vbQuestion + vbYesonly, "Unknown Vehicle...")
Response = acDataErrContinue
Forms!vehicle!VehName.SetFocus
200 Exit Sub
End Sub
When it returns it goes to the field ON THE SUBFORM that it started in -
not
the parent form
 
Hi Nylex,
the Before Insert event on the subform should do what you want.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
I am not quite sure how to do your suggestion - what to I alter

Jeanette Cunningham said:
Hi Nylex,
the Before Insert event on the subform should do what you want.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Nylex said:
If they try to enter a record without a selection in the parent form I
need
to return them to the main form - I have tried different ways but none
work -
this is my current try
Private Sub ModelName_Enter()
Dim StrName As String
Dim i As Integer
Dim Msg As String
StrName = Nz(Me.Parent![VehName])
If StrName = "" Then GoTo 100
GoTo 200
100
Msg = "'" & "' No Vehicle Name is Selected."
Msg = Msg & " - Select Vehicle Name"
i = MsgBox(Msg, vbQuestion + vbYesonly, "Unknown Vehicle...")
Response = acDataErrContinue
Forms!vehicle!VehName.SetFocus
200 Exit Sub
End Sub
When it returns it goes to the field ON THE SUBFORM that it started in -
not
the parent form
 
Paste this function (from Allen Browne) in a module (not in code behind a
form).

Public Function RequireParent(frmMe As Form) As Integer
'Purpose: Require a record in the parent form.
' Usage: Set a subform's BeforeInsert property to:
' =RequireParent([Form])
' Return: Value that can be set to Cancel.
On Error GoTo Err_Handler
pstrProc = "RequireParent"
Dim strMsg As String
Dim frmParent As Form

Set frmParent = frmMe.Parent
If frmParent.NewRecord Then
MsgBox "Cancelled..."
DoCmd.CancelEvent
RequireParent = True
End If

Exit_Handler:
Set frmParent = Nothing
Exit Function

Err_Handler:
Msgbox Err.Number & " " & Err.Description
Resume Exit_Handler

End Function



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

Nylex said:
I am not quite sure how to do your suggestion - what to I alter

Jeanette Cunningham said:
Hi Nylex,
the Before Insert event on the subform should do what you want.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Nylex said:
If they try to enter a record without a selection in the parent form I
need
to return them to the main form - I have tried different ways but none
work -
this is my current try
Private Sub ModelName_Enter()
Dim StrName As String
Dim i As Integer
Dim Msg As String
StrName = Nz(Me.Parent![VehName])
If StrName = "" Then GoTo 100
GoTo 200
100
Msg = "'" & "' No Vehicle Name is Selected."
Msg = Msg & " - Select Vehicle Name"
i = MsgBox(Msg, vbQuestion + vbYesonly, "Unknown Vehicle...")
Response = acDataErrContinue
Forms!vehicle!VehName.SetFocus
200 Exit Sub
End Sub
When it returns it goes to the field ON THE SUBFORM that it started
in -
not
the parent form
 
Correction to last post, remove the line that says
pstrProc = "Require Parent"

Here is the correct function.

Paste this function (from Allen Browne) in a module (not in code behind a
form).

Public Function RequireParent(frmMe As Form) As Integer
'Purpose: Require a record in the parent form.
' Usage: Set a subform's BeforeInsert property to:
' =RequireParent([Form])
' Return: Value that can be set to Cancel.
On Error GoTo Err_Handler
pstrProc = "RequireParent"
Dim strMsg As String
Dim frmParent As Form

Set frmParent = frmMe.Parent
If frmParent.NewRecord Then
MsgBox "Cancelled..."
DoCmd.CancelEvent
RequireParent = True
End If

Exit_Handler:
Set frmParent = Nothing
Exit Function

Err_Handler:
Msgbox Err.Number & " " & Err.Description
Resume Exit_Handler

End Function


To use this function, find the BeforeInsert event of the subform.
Type the following in the space next to the name of the event
=RequireParent([Form])



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

Jeanette Cunningham said:
Paste this function (from Allen Browne) in a module (not in code behind a
form).

Public Function RequireParent(frmMe As Form) As Integer
'Purpose: Require a record in the parent form.
' Usage: Set a subform's BeforeInsert property to:
' =RequireParent([Form])
' Return: Value that can be set to Cancel.
On Error GoTo Err_Handler
pstrProc = "RequireParent"
Dim strMsg As String
Dim frmParent As Form

Set frmParent = frmMe.Parent
If frmParent.NewRecord Then
MsgBox "Cancelled..."
DoCmd.CancelEvent
RequireParent = True
End If

Exit_Handler:
Set frmParent = Nothing
Exit Function

Err_Handler:
Msgbox Err.Number & " " & Err.Description
Resume Exit_Handler

End Function



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

Nylex said:
I am not quite sure how to do your suggestion - what to I alter

Jeanette Cunningham said:
Hi Nylex,
the Before Insert event on the subform should do what you want.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


If they try to enter a record without a selection in the parent form I
need
to return them to the main form - I have tried different ways but none
work -
this is my current try
Private Sub ModelName_Enter()
Dim StrName As String
Dim i As Integer
Dim Msg As String
StrName = Nz(Me.Parent![VehName])
If StrName = "" Then GoTo 100
GoTo 200
100
Msg = "'" & "' No Vehicle Name is Selected."
Msg = Msg & " - Select Vehicle Name"
i = MsgBox(Msg, vbQuestion + vbYesonly, "Unknown Vehicle...")
Response = acDataErrContinue
Forms!vehicle!VehName.SetFocus
200 Exit Sub
End Sub
When it returns it goes to the field ON THE SUBFORM that it started
in -
not
the parent form
 
Back
Top