Run-time error

A

Anthony

I am getting a weird run-time error. Maybe someone can help me figure out
what is happening. The run-time error I get is: "Run-time error 91"
"Object variable or With block variable not set". The error happens when
the database starts up.
When I click "End" it continues with starting up the database and doesn't
seem to affect anything.

I have several versions of the database, since I am constantly programming
new features. The odd thing about this is OLD versions of the program have
the run-time error also. Also, my colleagues that use the same version, do
NOT experience the error. Because of this, I am thinking it has nothing to
do with my code, but something with my Access startup process. That is why I
wrote this question here rather than in the Access Programming discussion
group. My startup process is somehow different than everyone else's.

Here is the offending code. In the function "Changeproperty" I have
highlighted the offending line with ">>>>"

Any help would be appreciated.

Function AutoExec()
On Error GoTo autoexec_err

DoEvents
DoCmd.Echo False
'ChangeProperty "StartupForm", dbText, "Main Menu"
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
ChangeProperty "AllowFullMenus", dbBoolean, True
ChangeProperty "AllowSpecialKeys", dbBoolean, True
DoCmd.ShowToolbar "Menu Bar", acToolbarNo
DoCmd.ShowToolbar "Database", acToolbarNo
DoCmd.ShowToolbar "Form View", acToolbarNo
DoCmd.ShowToolbar "Menu", acToolbarYes
DoCmd.ShowToolbar "Print Preview", acToolbarNo
DoCmd.ShowToolbar "Formatting (Form/Report)", acToolbarNo
'DoCmd.ShowToolbar "Find", acToolbarNo
DoCmd.Echo True

Autoexec_exit:
Exit Function

autoexec_err:
DoCmd.Echo True
MsgBox Err.Description, , Err.Number
Resume Autoexec_exit
Resume
End Function

Function ChangeProperty(strPropName As String, varPropType As Variant,
varPropValue As Variant) As Long
Dim dbs As Database, prp As Property
Const conPropNotFoundError = 3270

'Set dbs = CurrentDb
On Error GoTo Change_ErrChangeProperty = True

Change_Bye:
Exit Function

Change_Err:
If Err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
 
A

Arvin Meyer [MVP]

I'm not sure what else is wrong, but you cannot use the word "AutoExec" as a
function name. It is a reserved word.
 
J

Jim B

If The code you have listed is correct, you have commented out the line where
dbs is set (two lines above the error). There is an apostrophe in front of
the line.

'Set dbs = CurrentDb

The object dbs never gets set.
 
A

Anthony

Jim, I don't believe it. That was it. Somehow that line got commented out.
It now works flawlessly. Thank you so much. As for "autoexec" being a
reserve word, it is, BUT that tells Access to run a function when the
program starts.
 

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