Please review code-getting error 2001

A

Angie

I am just beginning VBA coding and have fell into having
to repair someone else's code in a critical database and
must get it repaired ASAP!

Here is the original code that seems to be causing the
problem:

Option Explicit


Function openNextFormCloseCurrent(FormNameToOpen As
String, curForm As String)
Dim stLinkCriteria As String
Dim frmCurrentForm As String
Dim stDoc1 As String

frmCurrentForm = curForm
stDoc1 = FormNameToOpen

DoCmd.OpenForm stDoc1, , , stLinkCriteria

DoCmd.Close acForm, frmCurrentForm
End Function

Function FilterNextFormCloseCurrent(FormNameToOpen As
String, curForm As String, intID As Integer)
Dim stLinkCriteria As String
Dim stDoc1 As String
Dim frmCurrentForm As String
Dim intProjCriteria As Integer

intProjCriteria = intID

frmCurrentForm = curForm
stDoc1 = FormNameToOpen
stLinkCriteria = "[ImprovProjMainTblID]=" &
intProjCriteria

DoCmd.OpenForm stDoc1, , , stLinkCriteria

DoCmd.Close acForm, frmCurrentForm
End Function

I have added exit statements and error handling but after
almost a week without the error it has recurred. I can
not open the forms in any view. I was told the person
who wrote the code "fixed" the problem by deleting the
forms and re-importing them from a backup.

Your help is greatly appreciated!




Expand AllCollapse All


Manage Your Profile |Rules of Conduct
©2004 Microsoft Corporation. All rights reserved. Terms of Use |Trademarks |Privacy Statement
 
P

Paul Johnson

I don't understand why the forms aren't opening. I noticed that you didn't
specify a View parameter, but the default view for forms is acViewNormal, so
it shouldn't be a problem. Is it possible that the form is already open
behind another window? If it is, the DoCmd.OpenForm method will fail.

Without solving the main problem, I will offer that the code gets very
cluttered when the values passed in as parameters get dimensioned and
renamed as new variables before you use them. This is unnecessary. And
finally, since these are subroutines, it would be a good idea to call them
Subs. Subs run procedures without returning values, while Functions return
values. A small point, but it keeps the code from getting too confusing:

Private Sub OpenNextFormCloseCurrent( _
frmToOpen As String, frmCurrent As String)
DoCmd.OpenForm frmToOpen
DoCmd.Close acForm, frmCurrent
End Sub

Private Sub FilterNextFormCloseCurrent( _
frmToOpen As String, frmCurrent As String, intID As Integer)
Dim stLinkCriteria as String
stLinkCriteria = "[ImprovProjMainTblID]=" & intID
DoCmd.OpenForm frmToOpen , , , stLinkCriteria
DoCmd.Close acForm, frmCurrent
End Sub

Good luck
Paul Johnson
 
K

Ken Snell

What error message are you getting? 2001 is an object-specific error so need
to know the message.

The fact that you cannot open the forms at all even in design view does
suggest that they are corrupted. You may need to import them into the backup
database and start again with them. Or open a new database and import them
from the original database.
 

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