Change database title using VBA

Is is possible to change the title of a Microsoft Access database programmatically using VBA?   I use Access.setOption for various global options in my database, but cannot find the code for changing the title.
Mel BrooksCITOAsked:
Who is Participating?

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

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.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
You mean the main window title?

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Using a Windows API call is one way to do that.


At the top of a standard module:

Declare Function wu_SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String) As Long

Then paste in the routine:

' Function: AccessSetCaption ()
' This function will set the caption of
' Microsoft Access's main window.
Public Function AccessSetCaption(strCaption as string) as long

10      AccessSetCaption = wu_SetWindowText(Application.hWndAccessApp, strCaption)

End Function
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
It's a function BTW so you can call it from the AutoExec macro.

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Dale FyeOwner, Developing Solutions LLCCommented:
Public Sub AppTitle()

    Dim prp As Property
    On Error Resume Next
    CurrentDb.Properties("AppTitle").Value = "Test Title"
    If Err.Number <> 0 Then
        Set prp = CurrentDb.CreateProperty("AppTitle", dbText, "Test Title Added")
        CurrentDb.Properties.Append prp
    End If
End Sub

Open in new window

If the property already has a value, then line 6 will not raise an error, but if there is no value in the property when this is run, you will need to create the property.

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
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
You'll want to call for a refresh of the title bar if you go with adding the AppTitle property:


Dale FyeOwner, Developing Solutions LLCCommented:
good suggestion, Jim.

I usually just use this in the code that I use to publish updates to the database, so after running that, and setting a bunch of other properties, I just close the database, so I don't need to do that step.

Mel BrooksCITOAuthor Commented:
This worked great.  Thanks
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

From novice to tech pro — start learning today.