The OpenForm action was canceled

M

mikefitzge

I'm getting the error "The OpenForm action was canceled" when I click
on the button to open a form. When I try to open the form in the
database window I get the following error:

"The expression On Open you entered as the event property setting
produced the following error:
*The expression may not result in the name of a macro, the name of
a user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event or
macro."

I have the following code on the On Open event of the form:

Private Sub Form_Open(Cancel As Integer)
DoCmd.GoToRecord , , acNewRec
Me.dtmDateConcreteCount.SetFocus
Me.cmdCount.Visible = True

Dim DateCount As Integer

DateCount = 0

Set rst = CurrentDb.OpenRecordset("SELECT
tblConcreteStatus.dtmDateConcreteCount FROM tblConcreteStatus")
Do Until rst.EOF = True
If rst!dtmDateConcreteCount = Date Then DateCount = DateCount + 1
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
If DateCount = 1 Then
Me.lblCountDone.Visible = True
Me.lblCountNotDone.Visible = False
ElseIf DateCount = 0 Then
Me.lblCountDone.Visible = False
Me.lblCountNotDone.Visible = True
Else
MsgBox ("You may have more than one Date Count for the same
day. Contact Mike about fixing this.")
End If

End Sub


dtmDateConcreteCount, cmdCount, lblCountDone, and lblCountNotDone are
all controls on the form.

Is there a problem in my code I'm not seeing? Or could the problem be
somewhere else? Any help would be appreciated.

Thanks,
Mike.
 
G

Guest

Move your code to the Load event. The Open event is way too soon. All the
controls have not been instansiated during the Open. By the time you get to
the Load event they have.
The Open event is better for determining whether you want to display the
form or not. It can be canceled. The Load event is better for preparing the
environmet.
 
M

mikefitzge

I dimensioned rst as a recordset and moved it all to the load event and
i did not get the error... thanks guys!

Move your code to the Load event. The Open event is way too soon. All the
controls have not been instansiated during the Open. By the time you get to
the Load event they have.
The Open event is better for determining whether you want to display the
form or not. It can be canceled. The Load event is better for preparing the
environmet.

mikefitzge said:
I'm getting the error "The OpenForm action was canceled" when I click
on the button to open a form. When I try to open the form in the
database window I get the following error:

"The expression On Open you entered as the event property setting
produced the following error:
*The expression may not result in the name of a macro, the name of
a user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event or
macro."

I have the following code on the On Open event of the form:

Private Sub Form_Open(Cancel As Integer)
DoCmd.GoToRecord , , acNewRec
Me.dtmDateConcreteCount.SetFocus
Me.cmdCount.Visible = True

Dim DateCount As Integer

DateCount = 0

Set rst = CurrentDb.OpenRecordset("SELECT
tblConcreteStatus.dtmDateConcreteCount FROM tblConcreteStatus")
Do Until rst.EOF = True
If rst!dtmDateConcreteCount = Date Then DateCount = DateCount + 1
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
If DateCount = 1 Then
Me.lblCountDone.Visible = True
Me.lblCountNotDone.Visible = False
ElseIf DateCount = 0 Then
Me.lblCountDone.Visible = False
Me.lblCountNotDone.Visible = True
Else
MsgBox ("You may have more than one Date Count for the same
day. Contact Mike about fixing this.")
End If

End Sub


dtmDateConcreteCount, cmdCount, lblCountDone, and lblCountNotDone are
all controls on the form.

Is there a problem in my code I'm not seeing? Or could the problem be
somewhere else? Any help would be appreciated.

Thanks,
Mike.
 
M

mikefitzge

I continue to get this error on an intermittent (yet frequent enough to
be quite annoying) basis. I tried both of the above suggestions and it
will work sometimes and not other times.

Does anyone have any idea why I may receive this error sometimes, and
not others? It seems to have no relation to when I do or do not
compact and repair.

Thanks,
Mike
 

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