Can't set DisplayForm database property

I am using this code to set the DisplayForm property of my application:


---BEGIN CODE---

Call ChangeProperty("DisplayForm", dbText, "FRM_Switchboard")
Application.Quit


Public Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Boolean
'---------------------------------------------------------------------'
' Module: ChangeProperty                                             '
' Date: July 18, 2003
' From:  MadMaxx (access-programmers.co.uk)
'---------------------------------------------------------------------'
  Dim db As Database, prp As Property
  Const conPropNotFoundError = 3270

  On Error GoTo Change_Err
  Set db = CurrentDb
  db.Properties(strPropName) = varPropValue
  ChangeProperty = True
  Exit Function

Change_Err:
  If Err = conPropNotFoundError Then
    Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
    db.Properties.Append prp
    Resume Next
  Else
    ChangeProperty = False
    Exit Function
  End If

---END CODE---

When I execute the code, the DisplayForm property is not set.  The next time the application comes up the Display Form doesn't automatically start up.

When I single-step through this code the DisplayForm property appears to be set, but when I click File > Options > Current Database the property is not set, and when the application ends and I bring it back up the Display Form is not set.

What is happening?  Why does the property think it is set, but not really?  How can I get the property to truly set?

This code is in the OnClick event for the Exit button of the FRM_Switchboard form.  I have set up the application so that the only way to exit the application is by clicking the Exit button.  If the user is somehow able to change or unset the DisplayForm property then this code is supposed to set it back to the default to prevent the user from bringing up the application without the Display Form coming up.

Any ideas would be much appreciated.

I have attached a simple app that has the same issue.
DisplayForm.accdb
koughdurAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nick67Commented:
When I single-step through this code the DisplayForm property appears to be set, but when I click File > Options > Current Database the property is not set

The db.Properties collection is a fun little bit of work.
It is a sparse collection, meaning that the keys AND values don't exist until you create them both either through the GUI or code.

I suspect that your code is not functioning the way you desire.
Try stepping it through.
If you create a value for the displayform through the GUI, the error-handling will never get hit again.
Until it is successfully created, you'll hit error-handling each time

  Dim db As Database, prp As Property
   Const conPropNotFoundError = 3270

   On Error GoTo Change_Err
   Set db = CurrentDb
   db.Properties(strPropName) = varPropValue
   ChangeProperty = True
   Exit Function

 Change_Err:
   msgbox err.number & " is the number --is that the right one?"
   If Err = conPropNotFoundError Then
     Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
     db.Properties.Append prp
     'this should create the property, so there will be no need for a return
     'test that assumption
     msgbox strPropName & " was created with a value of " & db.Properties(strPropName)
     ChangeProperty = True
     Exit Function
     'Resume Next
   Else
     ChangeProperty = False
     Exit Function
   End If
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
koughdurAuthor Commented:
I added your suggested code and I got the message that the DisplayForm  property was created with the value 'FRM'.

This is the same result I got when single-stepping through the code and printing the values in the Immediate Window.

Still the DisplayForm property won't really set.  I added:

db.Properties.Refresh

but that didn't help either.  I even dropped and recreated the property without success.

Any more ideas?
0
koughdurAuthor Commented:
I did some searching and even though MS Access calls it 'DisplayForm' on the interface, the correct property I should have been setting was 'StartUpForm'.  When I created/set that property then the form comes us the next time I bring up the application.

Properties are very funny indeed.
0
koughdurAuthor Commented:
Thanks for responding quickly.  Got me to thinking that maybe I wasn't setting the correct property.
0
Nick67Commented:
Properties are very funny indeed
They are odd in that they do not exist until you make them -- and yet you have to make very specific things if you want them to work.
But, the db.Properties one is extra odd.  With that one, you are actually permitted to create user-specific properties and retrieve and use them as YOU see fit.  Field.Properties is not that way.  Either you create a proper one of you get BANG!
There's a nice discussion of the MS-defined strings required for db.Properties here
http://bytes.com/topic/access/answers/926248-possible-set-access-startup-options-using-vba
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.