From: Shairal on
I have create a CloseButton on my main form - the generated code is:

Private Sub CloseButton_Click()
On Error GoTo Err_CloseButton_Click
On Error GoTo Err_CloseButton_Click
DoCmd.Close
Exit_CloseButton_Click:
Exit Sub
Err_CloseButton_Click:
MsgBox Err.Description
Resume Exit_CloseButton_Click
End Sub

I want to add an IF statement so if a field on a subform is left blank I
want the user to be brought back to the empty field so they enter data before
closing the main form - I have something like this but I keep getting errors
that it cannot find the field

Dim strMsg As String, strTitle As String
Dim intStyle As Integer

On Error GoTo Err_CloseButton_Click

If IsNull(Forms![MainForm![SubForm]Form.Control) Then
Forms![MainForm![SubForm]Form.Control.SetFocus
strMsg = "Enter product code."
strTitle = "Product code missing"
intStyle = vbOKOnly

Else
DoCmd.Close

End If

Can someone tell me where my mistake is - I cannot seem to fix it?
THANKS!!

From: Lord Kelvan on
oh the pain you are using subforms...

Private Sub btnclose_Click()
If IsNull(Forms![frmMainForm]![frmsubform]!subformcontrol.Value)
Or Forms![frmMainForm]![frmsubform]!subformcontrol.Value = "" Then
MsgBox "Enter product code.", vbOKOnly, "Product code missing"
Forms![frmMainForm]![frmsubform].SetFocus
Forms![frmMainForm]![frmsubform]!subformcontrol.SetFocus
Else
DoCmd.Close
End If
End Sub

also as a note you need to set focus to the subform first before you
can set focus tot he control on the subform


this is your problem Form.Control

Regards
Kelvan