Opening a database with VBA

B

Bill B

I keep getting the error " Object variable or With block variable not set"
with running this function and the "ref_intOpenDatabase_CurrentDB" getsa
called.

Is there any otehr way to open an database other then like I am??

*****************
Function ref_intOpenDatabase(ByVal pstrDB As String) As Integer
On Error GoTo ref_intOpenDatabase_Err

Dim intRet As Integer
Dim strCurrDB As String
Const NO_DB_OPEN = 7952 '= Illegal function Call - no current
database

' special error handler to catch when no database is opened.
On Error GoTo ref_intOpenDatabase_CurrentDB

strCurrDB = mappAccess.CurrentDb.Name()

On Error GoTo ref_intOpenDatabase_Err

If strCurrDB <> pstrDB Then
mappAccess.CloseCurrentDatabase
End If

ref_intOpenDatabase_OPEN:

mappAccess.OpenCurrentDatabase mstrAccappPath & pstrDB, False

intRet = True

ref_intOpenDatabase_Exit:
ref_intOpenDatabase = intRet
Exit Function

ref_intOpenDatabase_Err:

intRet = False
MsgBox "_Err Error: " & Error$, vbExclamation, "ref_intOpenDatabase()"
Resume ref_intOpenDatabase_Exit

ref_intOpenDatabase_CurrentDB:
If Err = NO_DB_OPEN Then
Resume ref_intOpenDatabase_OPEN
Else
intRet = False
MsgBox "_CurrentDB Error: " & Error$, vbExclamation,
"ref_intOpenDatabase()"
Resume ref_intOpenDatabase_Exit
End If


End Function

*******************

Bill
 

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