Solved

Setting "Tabbed Documents" via VBA on an MS Access 2010 database

Posted on 2014-03-31
6
1,948 Views
Last Modified: 2014-04-06
To whom it may concern:
Could you tell me how to programmatically (VBA) set an MS Access 2010 database to "Tabbed Documents" instead of "Overlapping Windows"?  I am creating a new MS Access 2010 database and I would like it to have this feature when a user opens the database.  I have tried the two sets of code below and they both don't seem to work.  I am not sure why either.

Try 1:
    Call SetPropertyDAO(db, "AllowDatasheetSchema", dbBoolean, False, strMsg)
    Call SetPropertyDAO(db, "DesignWithData", dbLong, mlngcAllowLayoutView, strMsg)
   
    'Preferences for child windows.
    Call SetPropertyDAO(db, "UseMDIMode", dbByte, 0, strMsg)
    Call SetPropertyDAO(db, "ShowDocumentTabs", dbBoolean, True, strMsg)

Try 2:
  db.Properties("UseMDIMode") = 0

Thank you for your help.
0
Comment
Question by:kylelinkuhn
  • 3
  • 3
6 Comments
 
LVL 84
ID: 39967314
What does "SetProperty" do?

Remember that many of the Access properties do not exist until needed, so often you must create the property if it's missing, so your "ShowDocumentTabs" property may not yet exist.
0
 

Author Comment

by:kylelinkuhn
ID: 39967335
Sorry about that.  Here are the procedures that are missing from my explanation above.


Private Function SetPropertyDAO(obj As Object, strPropertyName As String, intType As Integer, _
    varValue As Variant, Optional strErrMsg As String) As Boolean
On Error GoTo ErrHandler
    'Purpose:   Set a property for an object, creating if necessary.
    'Arguments: obj = the object whose property should be set.
    '           strPropertyName = the name of the property to set.
    '           intType = the type of property (needed for creating)
    '           varValue = the value to set this property to.
    '           strErrMsg = string to append any error message to.

    If HasProperty(obj, strPropertyName) Then
        obj.Properties(strPropertyName) = varValue
    Else
        obj.Properties.Append obj.CreateProperty(strPropertyName, intType, varValue)
    End If
    SetPropertyDAO = True

ExitHandler:
    Exit Function

ErrHandler:
    strErrMsg = strErrMsg & obj.Name & "." & strPropertyName & " not set to " & varValue & _
        ". Error " & Err.Number & " - " & Err.Description & vbCrLf
    Resume ExitHandler
End Function

Private Function HasProperty(obj As Object, strPropName As String) As Boolean
    'Purpose:   Return true if the object has the property.
    Dim varDummy As Variant

    On Error Resume Next
    varDummy = obj.Properties(strPropName)
    HasProperty = (Err.Number = 0)
End Function
0
 
LVL 84
ID: 39967503
What is the value of "db"? That would need to be set to CurrentDb, or something of that nature.

Otherwise, the code looks like it should work.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:kylelinkuhn
ID: 39967554
db is the database that I want the "Tabbed Documents" to be set on, which is not the current database.  If I set db to the current db, will the database I create from it be set as "Tabbed Documents"?
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 39967693
Yes, it should. But assuming you've set the "db" variable correctly, the code you show should work.

Can you set a breakpoint and see what's happening in the SetPropertyDAO code?
0
 

Author Closing Comment

by:kylelinkuhn
ID: 39981608
I figured out what I had done incorrectly.  The code worked correctly.  I thought I had the CurrentDb set correctly, but I didn't.  Thanks for your help.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now