problem with subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Guys

I hope someone can help me with this.

I have a client data entry form for users to enter new client details. The
problem is with its embedded subform on which I want users to enter a start
date for a training course. I have put in some code to trap for this in the
before update event. This works fine if users enter other info in the
subform, however if the user closes the client data entry form without
entering anything in the subform this code obviously wont fire.

To get round this I have added the following code to my close form command
button:

Private Sub cmdClosefrm_Click()
On Error GoTo Err_cmdClosefrm_Click

If IsNull(Me!fsubStartLeave.Form!txtStartDate.Value) Then

MsgBox "Please enter start date.", vbExclamation + vbOK, "MISSING START DATE."
Cancel = True
Me!fsubStartLeave.Form!txtStartDate.SetFocus

Else
DoCmd.Close
End If
Exit_cmdClosefrm_Click:
Exit Sub

Err_cmdClosefrm_Click:
MsgBox Err.Description
Resume Exit_cmdClosefrm_Click
End Sub

It is nearly right but for some reason the focus remains on the close form
command button rather than moving to the control on the subform.

Can anyone suggest changes to my code so that it does what I want it to.

Thank you for any help or advice.

Chris
 
add me.fsubStartLeave.setfocus before you set focus to a control on the subform.


| Hi Guys
|
| I hope someone can help me with this.
|
| I have a client data entry form for users to enter new client details. The
| problem is with its embedded subform on which I want users to enter a start
| date for a training course. I have put in some code to trap for this in the
| before update event. This works fine if users enter other info in the
| subform, however if the user closes the client data entry form without
| entering anything in the subform this code obviously wont fire.
|
| To get round this I have added the following code to my close form command
| button:
|
| Private Sub cmdClosefrm_Click()
| On Error GoTo Err_cmdClosefrm_Click
|
| If IsNull(Me!fsubStartLeave.Form!txtStartDate.Value) Then
|
| MsgBox "Please enter start date.", vbExclamation + vbOK, "MISSING START DATE."
| Cancel = True
| Me!fsubStartLeave.Form!txtStartDate.SetFocus
|
| Else
| DoCmd.Close
| End If
| Exit_cmdClosefrm_Click:
| Exit Sub
|
| Err_cmdClosefrm_Click:
| MsgBox Err.Description
| Resume Exit_cmdClosefrm_Click
| End Sub
|
| It is nearly right but for some reason the focus remains on the close form
| command button rather than moving to the control on the subform.
|
| Can anyone suggest changes to my code so that it does what I want it to.
|
| Thank you for any help or advice.
|
| Chris
|
 
Hi Debbie

Thank you very much.Thats great it works perfectly now...if only everything
in life were that simple <bg>

Thanks again

Chris
 
I wish!


| Hi Debbie
|
| Thank you very much.Thats great it works perfectly now...if only everything
| in life were that simple <bg>
|
| Thanks again
|
| Chris
|
| "DebbieG" wrote:
|
| > add me.fsubStartLeave.setfocus before you set focus to a control on the
subform.
| >
| >
| > | > | Hi Guys
| > |
| > | I hope someone can help me with this.
| > |
| > | I have a client data entry form for users to enter new client details. The
| > | problem is with its embedded subform on which I want users to enter a
start
| > | date for a training course. I have put in some code to trap for this in
the
| > | before update event. This works fine if users enter other info in the
| > | subform, however if the user closes the client data entry form without
| > | entering anything in the subform this code obviously wont fire.
| > |
| > | To get round this I have added the following code to my close form command
| > | button:
| > |
| > | Private Sub cmdClosefrm_Click()
| > | On Error GoTo Err_cmdClosefrm_Click
| > |
| > | If IsNull(Me!fsubStartLeave.Form!txtStartDate.Value) Then
| > |
| > | MsgBox "Please enter start date.", vbExclamation + vbOK, "MISSING START
DATE."
| > | Cancel = True
| > | Me!fsubStartLeave.Form!txtStartDate.SetFocus
| > |
| > | Else
| > | DoCmd.Close
| > | End If
| > | Exit_cmdClosefrm_Click:
| > | Exit Sub
| > |
| > | Err_cmdClosefrm_Click:
| > | MsgBox Err.Description
| > | Resume Exit_cmdClosefrm_Click
| > | End Sub
| > |
| > | It is nearly right but for some reason the focus remains on the close form
| > | command button rather than moving to the control on the subform.
| > |
| > | Can anyone suggest changes to my code so that it does what I want it to.
| > |
| > | Thank you for any help or advice.
| > |
| > | Chris
| > |
| >
| >
| >
 
Back
Top