PC Review


Reply
Thread Tools Rate Thread

Add code to CloseButton

 
 
Shairal
Guest
Posts: n/a
 
      27th May 2010
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!!

 
Reply With Quote
 
 
 
 
Lord Kelvan
Guest
Posts: n/a
 
      28th May 2010
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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closebutton vs. DoCmd.Close =?Utf-8?B?Sm9u?= Microsoft Access Form Coding 11 6th Jun 2007 03:57 PM
Closebutton R. Choate Microsoft Access Form Coding 1 15th Oct 2005 02:20 AM
set .ContolBox and .CloseButton to yes Angi Microsoft Access Form Coding 3 14th Feb 2005 10:00 PM
Re: CloseButton Property TC Microsoft Access Form Coding 0 21st Nov 2003 12:02 AM
Forms CloseButton Property Jerry McCutchen Microsoft Access VBA Modules 2 19th Nov 2003 09:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:33 PM.