Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Additional code for close button

Status
Not open for further replies.

tshudt

Programmer
May 16, 2005
8
US
I have a command button that will close a form.(the button is on the main form) I would like to add code to the close button that checks to see if information is entered in the subform and if there is information then check to make sure there is a Date entered on the main form. if there is no date then have a message pop up and tell the user to enter a Date. If when the button is clicked and there is a date entered on the main form then just close the form.

Any help would be greatly appreciated

Tim
 
Tim,

Something like this could work (substitute YOUR names for the names in blue):
Code:
If Not IsNull Me![COLOR=blue][b]MySubform[/b][/color]![COLOR=blue][b]MySubformField[/b][/color] Then
    If IsNull(Me![COLOR=blue][b]MyDateField[/b][/color]) Then
        Cancel = True
        MsgBox "You must enter a date before exiting."
        Me![COLOR=blue][b]MyDateField[/b][/color].SetFocus
        Exit Sub
    End If
End If

HTH,

Ken S.
 
Hey there,

I suggest using something like the suggestion above in conjunction with the code found in faq702-2071. It really makes the close button effective.

Good luck,
MJG
 
How are ya tshudt . . . . .

In the [blue]UnLoad[/blue] event of the form, copy/paste the following:
Code:
[blue]   Dim sfrm As Form
   
   Set sfrm = Me!subFormName.Form
   
   If sfrm.RecordsetClone.RecordCount And _
      IsNull(Me!DateCtlName) Then
      MsgBox "YourMessageHere"
      Me!DateCtlName.SetFocus
      Cancel = True
   End If
   
   Set sfrm = Nothing[/blue]
[purple]You did'nt address what to do if the subform has no records![/purple]

Calvin.gif
See Ya! . . . . . .
 
If the subform has no records then just close the form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top