Setting Focus after error

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
 
F

far

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
 
J

Jeanette Cunningham

Hi Nylex,
the Before Insert event on the subform should do what you want.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
N

Nylex

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
 
J

Jeanette Cunningham

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
 
J

Jeanette Cunningham

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
 

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