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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using DoCmd.OpenForm causes error 2501 1

Status
Not open for further replies.

scottintexas

Programmer
Feb 27, 2006
12
US
I'm trying to open a pop up form. I have tried
Code:
docmd.openform FormName:="frmCounty", WindowMode:=acDialog

and
Code:
DoCmd.OpenForm "frmNewCounty", , , , , acDialog

Either one generates the error; "The OpenForm action was canceled"

I just can't see what's wrong with this.

ScottInTexas
It's probably as hard as it looks.
 
In this case I think it is because you have not spelled the name of the form correctly. You already have it two different ways. What is the actual name of the form?

HTH RuralGuy (RG for short) acXP winXP Pro
Please respond to this forum so all may benefit
 
It is frmNewCounty. I just typed it here incorrectly. I checked my code and it is spelled correctly there.

ScottInTexas
It's probably as hard as it looks.
 
Do you have some code in the Open event of the form that would cancel the open? Try without the acDialog to see if it makes any difference.

HTH RuralGuy (RG for short) acXP winXP Pro
Please respond to this forum so all may benefit
 
Tried it without the acDialog. No change. I think the open is being canceled because of another error in the form. It has been a long time sincec I have had to write any code so a lot is VERY rusty. I want the user to type a name in a text box and when the window is closed then take the value and work with it. So I tried to set it up with a property. When the user types the name in the text box then clicks OK the property is set and the form is hidden. Then in the calling function I can get the value of the property and finally close the form. So this is what I have:
Code:
'Calling function
Private Const strCountyForm As String = "frmNewCounty"

Public Function adhDoCounties() As Variant
    DoCmd.OpenForm FormName:=strCountyForm, WindowMode:=acDialog
    
    If IsOpen(strCountyForm) Then
        strDoCounties = Forms(strCountyForm).CountyName
    Else
        strDoCounties = Null
    End If
End Function

Public Function IsOpen(strName As String, Optional lngObjectType As AcObjectType = acForm) As Boolean
    IsOpen = (SysCmd(acSysCmdGetObjectState, lngObjectType, strName) <> 0)
End Function

'form

Option Compare Database
Private strCounty As String

Public Property Set County(NewCounty As String)
    strCounty = NewCounty
End Property

Public Property Get County() As String
    County = strCounty
End Property
Private Sub cmdAdd_Click()
    County = Me.txtCountyName
    Me.Visible = False
End Sub

Private Sub cmdCancel_Click()
    DoCmd.Close acForm
End Sub

Hope that helps with debugging this itty bitty piece of code that I should be able to write without an error.


ScottInTexas
It's probably as hard as it looks.
 
This is now working just as it is programmed. Nothing has changed. I have closed and re-opened the form with the calling function and that seems to have fixed the problem. Thanks for your help.

ScottInTexas
It's probably as hard as it looks.
 
Thanks for posting back.

HTH RuralGuy (RG for short) acXP winXP Pro
Please respond to this forum so all may benefit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top