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!

How to close a form in sub Form_Open()

Status
Not open for further replies.

xenofoob

Programmer
Oct 4, 2004
28
NL
Hello,

My Title is clear enough I hope ^o^

This is my piece of code:
Code:
Private Sub Form_Open(Cancel As Integer)
    If IsNull([factuur_datum]) Then
      'null
    Else
        Dim value As Integer
        value = MsgBox("Date = Null", vbOKCancel)
        If value = 2 Then
            DoCmd.Close
        End If
    End If
End Sub
Explaination:
This piece of code checks if the date field is empty or not. If not the user gets a confirmbox. When clicking the cancel button the form has to close.

Via this code I get an error message: "Microsoft Office Access can't find the form 'FactuurInvoeren' referred to in a macro expression or Visual Basic code."

How to close the form without any warnings or messages?

Thanks a lot!
 
The code looks alright to me but you are not telling Access what to close

try using
docmd.close acdefault
 
Still having the problem

The function close is being reached because a msgbox is showed.
 
What about:

Code:
Cancel = True

instead of Docmd?

combo
 
Never mind....

My problem was that there was a macro executed at button click to open the form 'FactuurInvoeren'...

Can happen if my friends create a form :p

Thanks for the suggestions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top