1 Replies - 3635 Views - Last Post: 02 October 2012 - 07:02 AM

#1 depricated  Icon User is online

  • DLN-000

Reputation: 714
  • View blog
  • Posts: 2,428
  • Joined: 13-September 08

Code 'stopped' working

Posted 02 October 2012 - 06:11 AM

I'm building a custom application in VBA over access(I'd rather do it in .NET considering, but boss insists it be inside access with VBA). I spent most of yesterday working on it, and today when I fired it up I started getting errors, where I wasn't last night. The last thing I did before leaving was verify that it worked, saved, and exited. This morning when I fired it up I'm getting an error 2501, "The OpenForm action was cancelled."

Here's the code calling the method:

Private Sub btnNewIncident_Click()

DoCmd.OpenForm "frmIncident", , , , , , "New"

End Sub


I actually can't get the form to load at all, it's weird. If I do just DoCmd.OpenForm "frmIncident" and comment out the entire Form_Open sub, it still gives me the same error.

Actually, just tried it again entirely removing the Form_Open sub and now it loads. If I change it to Form_Load it doesn't seem to run any of the code in the method though. Here's my open function.

Private Sub Form_Open(Cancel As Integer)
'-----------------------------------------------------------------------------
'This will run every time the form is Opened,
'and should determine what to do with it from the strArgs String.
'This is how we make the form dynamic.
'-----------------------------------------------------------------------------
Dim strArg As String 'arguments passed to the form
Dim boolLoad As Boolean 'this will be used to stop the form from loading

strArg = Me.OpenArgs
boolLoad = True
'check what we're being told to do when we open the form.
If strArg = "New" Then LoadNew 'we're creating a new incident, run the LoadNew function
If strArg = "Remedy" Then boolLoad = LoadRemedy 'we're going to open an incident by it's remedy ticket #
If strArg = "LastCreated" Then boolLoad = LoadLastCreated 'we're going to open the last ticket created by the user
If Not boolLoad Then DoCmd.Close

End Sub
I can't see where it's failing out. LoadLastCreated and LoadRemedy are bools that return true if they succeed in building the form.

Is there a reference or something I might be missing that's necessary for this to run properly?

Is This A Good Question/Topic? 0
  • +

Replies To: Code 'stopped' working

#2 depricated  Icon User is online

  • DLN-000

Reputation: 714
  • View blog
  • Posts: 2,428
  • Joined: 13-September 08

Re: Code 'stopped' working

Posted 02 October 2012 - 07:02 AM

I think I found the problem, which didn't seem to be causing trouble last night. Anyway, in LastCreated() I manipulate a Recordset, which isn't available during the Open process, but is during the Load process. Still, for some reason it wasn't running the code in the Form_Load() method either. I have it running down and changed the Form_Load to this(with no changes elsewhere) and its running:
Private Sub Form_Load()
'-----------------------------------------------------------------------------
'This will run every time the form is Opened,
'and should determine what to do with it from the strArgs String.
'This is how we make the form dynamic.
'-----------------------------------------------------------------------------
Dim boolLoad As Boolean 'this will be used to stop the form from loading
MsgBox "test"
boolLoad = True
'check what we're being told to do when we open the form.
If Me.OpenArgs = "New" Then LoadNew 'we're creating a new incident, run the LoadNew function
If Me.OpenArgs = "Remedy" Then boolLoad = LoadRemedy 'we're going to open an incident by it's remedy ticket #
If Me.OpenArgs = "LastCreated" Then boolLoad = LoadLastCreated 'we're going to open the last ticket created by the user
If Not boolLoad Then DoCmd.Close

End Sub
No idea why it works like that and not the other way.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1