“Invalid procedure call or argumentâ€

S

Sharon

When I open my Access 2003 database, I receive an immediate error: “Invalid
procedure call or argumentâ€. The problem appears to be the code regarding
the Open_Reporter (see code below). I have a module named “Login Code†with
the code as shown below. I have checked to make sure that all the forms
exist, that there are no missing references etc. but just can’t figure out
what the problem is. If someone could give me some idea where to start it
would be extremely helpful. Thanks in advance.


Function ObjectExists(ObjType As Integer, ObjName As String) As Boolean
'Purpose: Determines whether or not a given object exists in database
'Example: If ObjectExists(acTable, "tblOrders") then ...

On Error Resume Next
Dim db As Database
Dim strTemp As String, strContainer As String
Set db = CurrentDb()

Select Case ObjType
Case acTable
strTemp = db.TableDefs(ObjName).Name
Case acQuery
strTemp = db.QueryDefs(ObjName).Name
Case acMacro, acModule, acForm, acReport
Select Case ObjType
Case acMacro
strContainer = "Scripts"
Case acModule
strContainer = "Modules"
Case acForm
strContainer = "Forms"
Case acReport
strContainer = "Reports"
End Select
strTemp = db.Containers(strContainer).Documents(ObjName).Name
End Select

ObjectExists = (Err.Number = 0)

End Function
__________________________________________________________
Function SQL_Link_ok() As Boolean
SQL_Link_ok = False
On Error GoTo ERROR
If Not ObjectExists(acQuery, "qrySQLTables") Then Exit Function
If IsNull(DLookup("Name", "qrySQLTables", "'ProfileFields'")) Then
Exit Function
Else
SQL_Link_ok = True
End If
ERROR:
End Function

_______________________________________________________
Function Open_Reporter()

If SQL_Link_ok Then
DoCmd.OpenForm "frmMainMenu", acNormal, "", "", , acNormal
DoCmd.Maximize
DoCmd.Close acForm, "frmOpen"
Else
DoCmd.OpenForm "frmConnect", acNormal, "", "", , acNormal
End If

Open_Reporter = 0

End Function
 
M

mscertified

Why not set a breakpoint and see exactly what statement is causing the error?

-Dorian
 
L

Larry Daugherty

Put in some actual error handling code. Try MZ Tools, its free and
very useful.

On Error Resume next won't help much. In Tools Options you might set
the choice to break on all errors...

HTH
 
S

Sharon

Not really familiar with all of the possibilities of debugging, but I have
tried to compile and toggle the breakpoint and it highlights the very first
line of the Open_Reporter ()" code.
 
R

Ray C

Hi Sharon,

I cleaned up a bit of your code. See if this works. I found several error
handling problems. Your OpenReporter function was assigned a value that
wasn't returned (forgot to put "As Integer" at the end of the header since it
always returns zero.

Here is my version:
-----------------------
Option Compare Database
Option Explicit

Public Function ObjectExists(ObjType As Integer, ObjName As String) As Boolean
On Error GoTo ErrFunction

Dim db As Database
Dim strTemp As String, strContainer As String
Set db = CurrentDb()

Select Case ObjType
Case acTable
strTemp = db.TableDefs(ObjName).Name
Case acQuery
strTemp = db.QueryDefs(ObjName).Name
Case acMacro, acModule, acForm, acReport
Select Case ObjType
Case acMacro
strContainer = "Scripts"
Case acModule
strContainer = "Modules"
Case acForm
strContainer = "Forms"
Case acReport
strContainer = "Reports"
End Select
strTemp = db.Containers(strContainer).Documents(ObjName).Name
End Select

ObjectExists = (Err.Number = 0)

ExitFunction:
Exit Function

ErrFunction:
MsgBox Err.Description
Resume ExitFunction

End Function

Public Function SQL_Link_ok() As Boolean
On Error GoTo ErrFunction

If Not ObjectExists(acQuery, "qrySQLTables") Then
SQL_Link_ok = False
ElseIf IsNull(DLookup("Name", "qrySQLTables", "'ProfileFields'")) Then
SQL_Link_ok = False
Else
SQL_Link_ok = True
End If

ExitFunction:
Exit Function

ErrFunction:
MsgBox Err.Description
Resume ExitFunction

End Function

Function Open_Reporter() As Integer
On Error GoTo ErrFunction

If SQL_Link_ok = True Then
DoCmd.OpenForm "frmMainMenu", acNormal, "", "", , acNormal
DoCmd.Maximize
DoCmd.Close acForm, "frmOpen"
Else
DoCmd.OpenForm "frmConnect", acNormal, "", "", , acNormal
End If

Open_Reporter = 0

ExitFunction:
Exit Function

ErrFunction:
MsgBox Err.Description
Resume ExitFunction

End Function

-----------------------
 
R

Ray C

Small error in my version:
In the ObjectExists function put back:
On Error Resume Next
at the beginning

See ya!
 

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