By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,678 Members | 1,904 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,678 IT Pros & Developers. It's quick & easy.

Help! Public variable not staying set - 3420 Object invalid or no longer set.

P: n/a
HELP!
Hi Folks,

I'm having trouble referencing these public variables, and I'm not sure
why. I use the code below to set open a connection to a database. The
variables are public variables and I hadn't had any problems previously, but
I seem to be having trouble now. I could have modified it between the time
it last worked and now (while I was cleaning up some of the code) but I
don't recall touching anything.

Right after I call this code, I do a
Debug.Print db.Name

and that throws the error
"3420 Object invalid or no longer set".

I've been beating my head against the wall wondering why this is. Any
ideas?

Thanks!

Public wksp As DAO.Workspace
Public db As DAO.Database

Function connectMyDb(Optional strlocation As String) As Boolean
On Error GoTo connectMyDb_Err

If strlocation = "" Then strlocation = getAttachment() ' If there is no
location specified, then get an attachment from existing attachments

DBEngine.SystemDB = "system.mdw"

Set wksp = CreateWorkspace("ModifyDb", "Admin", "", dbUseJet)

Set db = wksp.OpenDatabase(strlocation, False, False, ";pwd=" &
GetPassword())

connectMyDb = True

connectMyDb_Exit:
Exit Function

connectMyDb_Err:
If Err.Number = 3031 Then
'If this error is thrown, the user has entered a password on his or her
own database
SetCustomPassword
Resume
ElseIf Err.Number = 3051 Then
'MsgBox "Data file is read only. Cannot continue", vbCritical, "Read
Only Data file"
Resume connectMyDb_Exit
Else
MsgBox Err.Number & ": " & Err.Description, vbCritical, "Error
Connecting"
Resume connectMyDb_Exit
End Function

Dec 14 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Anybody at all?

"Jozef" <me@you.com> wrote in message news:4qLnf.147537$S4.28702@edtnps84...
HELP!
Hi Folks,

I'm having trouble referencing these public variables, and I'm not sure
why. I use the code below to set open a connection to a database. The
variables are public variables and I hadn't had any problems previously,
but I seem to be having trouble now. I could have modified it between the
time it last worked and now (while I was cleaning up some of the code) but
I don't recall touching anything.

Right after I call this code, I do a
Debug.Print db.Name

and that throws the error
"3420 Object invalid or no longer set".

I've been beating my head against the wall wondering why this is. Any
ideas?

Thanks!

Public wksp As DAO.Workspace
Public db As DAO.Database

Function connectMyDb(Optional strlocation As String) As Boolean
On Error GoTo connectMyDb_Err

If strlocation = "" Then strlocation = getAttachment() ' If there is no
location specified, then get an attachment from existing attachments

DBEngine.SystemDB = "system.mdw"

Set wksp = CreateWorkspace("ModifyDb", "Admin", "", dbUseJet)

Set db = wksp.OpenDatabase(strlocation, False, False, ";pwd=" &
GetPassword())

connectMyDb = True

connectMyDb_Exit:
Exit Function

connectMyDb_Err:
If Err.Number = 3031 Then
'If this error is thrown, the user has entered a password on his or her
own database
SetCustomPassword
Resume
ElseIf Err.Number = 3051 Then
'MsgBox "Data file is read only. Cannot continue", vbCritical, "Read
Only Data file"
Resume connectMyDb_Exit
Else
MsgBox Err.Number & ": " & Err.Description, vbCritical, "Error
Connecting"
Resume connectMyDb_Exit
End Function


Dec 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.