View Single Post
  #1  
Old May 27th, 2010, 11:51 PM posted to microsoft.public.access.forms
shairal
external usenet poster
 
Posts: 31
Default Add code to CloseButton

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!!