From Word to vbProject in Access database (Office 2000)

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15615
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

From Word to vbProject in Access database (Office 2000)

Post by ChrisGreaves »

I realize that Access is markedly different from everything else on this green earth, so my top-level question is "Ought I be able to do this?", that is, use Word 2000 to manage VBA code in an Access database as easily as I manage it (from Word 2000) in a workbook, document or project?

I write in Word2000 VBA.
From Word I can modify VBA code in Excel, Word and PPT applications, but I can't seem to do it with Access 2000 databases.
The code to access POWERPOINT and EXCEL code is quite similar:

Code: Select all

    Dim strTemplate As String
    strTemplate = UW.strBrowseFile(strcPowerPointProjectTypes)
    If Len(strTemplate) > 0 Then
        Dim xlApp As New PowerPoint.Application
        Dim docTemplate As PowerPoint.Presentation
        xlApp.Visible = msoTrue
        Set docTemplate = xlApp.Presentations.Open(strTemplate)

Code: Select all

    Dim strTemplate As String
    strTemplate = UW.Browsers.strBrowseFile2("", strcExcelProjectTypes, "J:")
    If Len(strTemplate) > 0 Then
        Dim xlApp As New Excel.Application
        Dim docTemplate As Excel.workbook
        Set docTemplate = xlApp.Workbooks.Open(strTemplate)
however in Access2000 i don't find the equivalent term for "Presentations" or "Workbooks":

Code: Select all

    Dim strTemplate As String
    strTemplate = UW.Browsers.strBrowseFile2("", strcAccessProjectTypes, "J:")
    If Len(strTemplate) > 0 Then
        Dim xlApp As New Access.Application
        Dim docTemplate
        Set docTemplate = xlApp.???.(strTemplate)
I tried using the DAO 3.6 library, but both these forms generate a syntax error "Expected Function or Variable"

Code: Select all

        Set docTemplate = xlApp.OpenCurrentDatabase(strTemplate)

Code: Select all

        Set docTemplate = xlApp.OpenAccessProject(strTemplate)
There's nothing heavier than an empty water bottle

User avatar
HansV
Administrator
Posts: 78466
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: From Word to vbProject in Access database (Office 2000)

Post by HansV »

You can have only one database open in Access, so OpenCurrentDatabase doesn't return an object. You call it like this:

xlApp.OpenCurrentDatabase strTemplate

Study up on the DoCmd object and the RunCommand instruction - they do most of the work in Access VBA.
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15615
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: From Word to vbProject in Access database (Office 2000)

Post by ChrisGreaves »

HansV wrote:xlApp.OpenCurrentDatabase strTemplate

Code: Select all

    Dim strTemplate As String
    strTemplate = UW.Browsers.strBrowseFile2("", strcAccessProjectTypes, "T:")
    If Len(strTemplate) > 0 Then
        Dim xlApp As New Access.Application
        xlApp.OpenCurrentDatabase strTemplate
        If blnTestLockedProject(xlApp.VBE.ActiveVBProject) Then
            Dim strMsg As String
            strMsg = "The project " & xlApp.VBE.ActiveVBProject.FullName & " is locked."
            strMsg = strMsg & vbCrLf & vbCrLf & "Please unlock it and try again."
            MsgBox strMsg
        Else
            Call ProjectStripper(os, xlApp.VBE.ActiveVBProject)
        End If
Appears to work (I'm too excited to run it all the way through the "ProjectStripper"; I wanted to post back and say THANKS HANS!)
Study up on the DoCmd object and the RunCommand instruction - they do most of the work in Access VBA.
I'll do this. I was told (something like) this two weeks ago.
I have to set aside some time to climb over the hurdle that holds me up.

I'm curious, though.
Why would I revert to the DoCmd object and the RunCommand instruction when I'm really working in Word?
My premise was that a VBProject is a VBProject is a VBProject, and a VBProject lives in a file which I open, after allowing the user to browse to a file.

I'm missing something here.
Probably best to toddle off and study Access in greater detail.

Thanks again for yet-another-hand-up!
There's nothing heavier than an empty water bottle

User avatar
HansV
Administrator
Posts: 78466
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: From Word to vbProject in Access database (Office 2000)

Post by HansV »

Sorry, a misunderstanding on my side. If you only want to manipulate the Visual Basic project of a database, you don't need to know about DoCmd and RunCommand; that would only be necessary if you wanted to control Access itself.
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15615
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: From Word to vbProject in Access database (Office 2000)

Post by ChrisGreaves »

HansV wrote:Sorry, a misunderstanding on my side. If you only want to manipulate the Visual Basic project of a database, you don't need to know about DoCmd and RunCommand; that would only be necessary if you wanted to control Access itself.
Not a problem.
I believe you are correct in saying I need to study up Access more; it is such a different beastie from The Rest Of The World.

The rewrite of the project manager a few years back was spurred by the comprehension that finally dawned on me that a VBProject is a VBProject is a VBProject, and that once I had the code to do really cute things with a Word VBproject, that code was directly applicable to any VBProject, which multiplied my Word efforts out to Excel and PPT (enough at the time to prove my point), and now out to Accesss. May as well do Project 2000 and Outlook while I'm at it ...

Once again, thank you for the helping hand; very much appreciated.
If Jezza ever threatens to visit Holland, feel free to send him over here instead; I'd be glad to straighten him out for you ....
There's nothing heavier than an empty water bottle