Run time error 2585

R

rafisch

The following code is used to open a new form - frmNewCompany to allo
the user to record a new company nam

Private Sub Company_DblClick(Cancel As Integer
DoCmd.OpenForm "FrmNewCompany", acNormal, , , acFormAdd, acDialo
DoCmd.GoToRecord , , acNewRe
End Su

If the user attempt to leave this form without entering a value in th
Company field he is prompted with a MsgBox with the option to continu
or cancel. The Continue action should close the from (frmNewCompany
however I am getting a 2585 erro

Private Sub Company_Exit(Cancel As Integer
Dim Prompt, buttons, Title, Respons
Dim intState As Intege
Dim intCurrentType As Intege
Dim strCurrentName As Strin
intCurrentType = Application.CurrentObjectTyp
strCurrentName = Application.CurrentObjectNam
Prompt = "You have not entred a valid name. Continue?
buttons =
Title = "Entering New Company
If IsNull(Me!Company) The
Response = MsgBox(Prompt, buttons, Title
If Response = 6 The
If (intCurrentType = 2 And strCurrentName = FrmNewCompany) The
DoCmd.Close intCurrentType, strCurrentName, acSaveN
End I
End I
End I
End Su

What am I doing wrong

Thank
 
W

Wayne Morgan

You ask if the user wants to continue exiting and if they answer Yes, you
tell the form to close. However, the form is already closing, that's why
you're in the Exit event. If you do nothing the form will close. By telling
the form to close in its Exit event, you've essentially set up an infinate
loop. Instead, if the user answers No, you need to cancel.
If Response = 6 Then
If (intCurrentType = 2 And strCurrentName = FrmNewCompany) Then
DoCmd.Close intCurrentType, strCurrentName, acSaveNo
End If
End If

If Response = 7 Then
If (intCurrentType = 2 And strCurrentName = FrmNewCompany) Then
Cancel = True
Exit Sub
End If
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top