A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Add code to CloseButton



 
 
Thread Tools Display Modes
  #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!!

  #2  
Old May 28th, 2010, 02:06 AM posted to microsoft.public.access.forms
Lord Kelvan
external usenet poster
 
Posts: 637
Default Add code to CloseButton

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
 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:21 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.