Link to home
Start Free TrialLog in
Avatar of aw labord
aw labord

asked on

MS Access: change Description of Form in Database Window in code

I am trying, unsuccessfully, to edit the Description of a Form listed in the Database Window.   When I create a new Form by copying another Form and editing the data fields, the Description of the new Form is the same as the old Form.  I need to change that information in code.  I can change it by right-clicking on the new Form and selecting Properties, but I would like to do it programmaticly.  Thank you.

I am using the MS Office Professional 2003 SP3 version of Access.  In VBA I am copying a Form named Test1 (with a Description in the Database Window of Test1) using CopyObject command.  I am naming the new Form Test2.  The copied Form appears in the Database Window correctly as Test 2, but with a Description of Test1.  In code, I need to change the Description of Test2 to read Test2.   Is this possible?   I can perform this task manually by right-clicking the Test2 Form , selecting Properties and changing the Description.
Avatar of ScriptAddict
ScriptAddict
Flag of United States of America image

I'm afraid you'll need to provide more information to get help.

What type of database?  MSSQL?  MySQL? Postgres?

What type of client are you using?  Is this a MS office Front end like an Access?  

Or are you coding it?  In c# or C++ or ??  what are you using to code it?  

All these things will bring in experts related to the specific question you have.  Without it, your question will likely just get ignored because the details aren't enough to draw the experts.

If I missed the details, I'm sorry, but I don't see anything.
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (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
Avatar of aw labord
aw labord

ASKER

Just curious...
Why does
DoCmd.CopyObject , varNewTblName, acTable, "MasterTable"
work OK and create a Table with a Description of varNewTblName, but
DoCmd.CopyObject , varNewFormName, acForm, "MasterForm"
does not (it copies the Description of MasterForm and requires your statement:
CurrentDB().Containers("Forms").Documents(varNewFormName).Properties("Description") = varNewFormName)?
I have made the adjustments and it seems to be working.
Thank you very much for your help.
Also, not that I need this feature right now, but are the DateCreated and DateModified fields also accessible in the same way?
And does your fix also apply to Queries, Reports, Pages, Macros and Modules?
Why does

 Don't know the answer to that directly, but it most likely stems from the fact that  tables (and queries) are slightly different than other objects as they are fundamental to the database engine, which Access is based on top of.   Forms, Reports, and Macro's represent "Access" objects, and code belongs to VBA.  

 What everyone thinks of as "Access" is really three separate components all talking to one another.  You have a database engine (JET/ACE), which Access uses to store things.   Those are the objects it defines and creates (forms, report, macro's, etc).  Then VBA is tacked on for a coding language, which gives you modules.

Also, not that I need this feature right now, but are the DateCreated and DateModified fields also accessible in the same way?

  Yes.  All the properties you see in the Nav Pane are properties of a Document object.  Some are predefined (like owner, date created, etc), while others are "custom" properties and are created as needed as part of the Properties Collection of the object.   Here you can see the database object, which has a lot of other properties, but also a properties collection:

User generated image
 So if you wanted to store an "AppVersion", you could do that here.   Also note that the Database object contains the "Containers" collection.  Each container object has a Documentes collection, consisting of Document Objects.

You can use the code below to explore a bit, which is some crude code I did many years ago.

Call it from the debug window with:

?  DisplayContainers("",-1)

to get a list of the containers, then:

? DisplayContainers("", x)

 where x is the container # you want to look at.

Jim.

Function DisplayContainers(strDatabase As String, intCollection As Integer) As Integer
    
    Dim DefaultWorkspace As Workspace
    Dim CurrentDatabase As Database
    Dim MyContainer As Container
    Dim MyDocument As Document

    Dim i As Integer
    Dim j As Integer

    Set DefaultWorkspace = DBEngine.Workspaces(0)
    
    If strDatabase = "" Then
        Set CurrentDatabase = DefaultWorkspace.Databases(0)
    Else
        Set CurrentDatabase = DefaultWorkspace.OpenDatabase(strDatabase)
    End If
    
    If intCollection = -1 Then
        For j = 0 To CurrentDatabase.Containers.Count - 1
            Set MyContainer = CurrentDatabase.Containers(j)
            Debug.Print ">> Container: "; j; " "; MyContainer.Name;
            Debug.Print ""
        Next j
    Else
        Set MyContainer = CurrentDatabase.Containers(intCollection)
        For i = 0 To MyContainer.Documents.Count - 1
            Set MyDocument = MyContainer.Documents(i)
            Debug.Print ""
            Debug.Print ""
            Debug.Print " > Document: "; MyDocument.Name;
            Debug.Print ""
            Debug.Print " > Owner: "; MyDocument.Owner;
            Debug.Print ""
            
            For intJ = 0 To MyDocument.Properties.Count - 1
              Debug.Print ">>> "; MyDocument.Properties(intJ).Name;
              Debug.Print ":"; MyDocument.Properties(intJ)
            Next intJ

        Next i
    End If

    If strDatabase <> "" Then
        CurrentDatabase.Close
        Set CurrentDatabase = Nothing
    End If
    
    DisplayContainers = True


End Function

Open in new window

Jim,
Thank you for your information on the workings of MS Access.   I like to know as much as I can about the database program with which I am most comfortable.  Where can I find the source for that DAO graphic you sent me?  
I guess from your response that the Description field is created correctly when copying a Table but needs your line of code when copying a Form.   I thought I must have been doing something wrong.
Alan
Where can I find the source for that DAO graphic you sent me?  

  That's the object browser built into the VBA editor window, which you can use to explore any lib you currently have a reference set for.


 You also can find object models online in various places.   Here's a couple:

DAO: http://codevba.com/msaccess/dao_objectmodeldiagram.xhtml#.W4PW1OhKhhE
Access:  http://codevba.com/msaccess/objectmodeldiagram.xhtml#.W4PWtOhKhhE

along with documentation on the models:

https://docs.microsoft.com/en-us/office/vba/api/overview/access/object-model

Jim.
Thank you again for all that information.  Now, if you could only tell me where to find a Fidelipac cart recorder for my Schulmerich 258-40 carillon, I would be eternally grateful.
Alan
Access is the specialty ;)
Just thought I'd ask anyway.  :-)