Link to home
Start Free TrialLog in
Avatar of kylelinkuhn
kylelinkuhn

asked on

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

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.
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

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.
Avatar of kylelinkuhn
kylelinkuhn

ASKER

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
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.
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"?
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.