Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Macro upgrade from word 2003 to word 2007

Posted on 2010-11-30
10
Medium Priority
?
348 Views
Last Modified: 2012-05-10
I have a customer who is upgrading from word 2003 to Word 2007.  They have a macro that writes a unique id and initials etc into the footer of the word document.

I can't seem to get this working.  I'm not a developer and ther person who wrote it orginally is no longer available.

i'm getting the following error message.

user defined type not defined.  Resolved this by adding in the reference "Microsoft DAO 3.51 Object Library.

Now getting the following error:

Complile error:  Invalid use of New keyword.

The following section is highlighted:

Function GetID() As String
On Error GoTo eh
    Dim cn As Connection, rs As Recordset
    Set cn = New Connection
    cn.Provider = "microsoft.jet.oledb.4.0"
    cn.ConnectionString = "\\fileserver\counter$\id.mdb"
    cn.Open
    Set rs = New Recordset
    rs.Open "SELECT * FROM idTable", cn, adOpenStatic, adLockOptimistic
    rs.AddNew
    rs.Update
    rs.MoveLast
    GetID = rs("ID")
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
    Exit Function
eh:
    MsgBox "An error occured " & Err.Description, vbInformation
End Function
0
Comment
Question by:mccannit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 19

Expert Comment

by:MINDSUPERB
ID: 34237647
The code you posted has reference to an access database which is remotely connected into your Word application. Ensure that the path of the database is correctly identified.

Sincerely,
Ed
0
 
LVL 1

Author Comment

by:mccannit
ID: 34237714
The path to the access database is fine.

Set cn = New Connection is the line that gets highlighted.    
0
 
LVL 19

Assisted Solution

by:MINDSUPERB
MINDSUPERB earned 2000 total points
ID: 34237772
Try to use ADO reference rather than DAO.

Sincerely,
Ed
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 76

Expert Comment

by:GrahamSkan
ID: 34237777
It looks as if it is written for ADO, not DAO. Try a reference to the Microsoft Active Data Objects library instead.
0
 
LVL 1

Author Comment

by:mccannit
ID: 34238076
that seemed to do the trick however I'm getting another error message.

I had to remove the "on error goto" to actually see the error message.

Run-time error '6':

Overflow.

I've included the actual macro "new file".  It's highlighting

strFooterText = CStr(Format(CInt(strId), "0000000")) _
                & "/" & strUser & "/" & strRequestee & "/" & strCaseRef & "/" & strDate
Sub NewFile()
    Dim docType As Integer, strRequestee As String
    Dim strCaseRef As String, strFileName As String
    Dim strId As String, strFooterText As String
    Dim strUser As String, strDate As String
    Application.ScreenUpdating = False
    docType = MsgBox("Is this a typing file, if so click the yes button, " _
    & vbCrLf & "if not click the no button", vbYesNo + vbQuestion, "Typing document?")
    If docType = vbYes Then
        frmLocation.Show vbModal
        'MsgBox strLocation
        strRequestee = InputBox("Enter the initials of the author", "Author Initials")
        If strRequestee = "" Then
            MsgBox "You Cancelled", vbInformation
        Else
            strCaseRef = InputBox("Enter the case reference", "Case reference", "Case Reference")
            If strCaseRef = "" Then
                MsgBox "You Cancelled", vbInformation
            Else
                strUser = Application.UserInitials
                strDate = CStr(Format(Date, "dd/mm/yy"))
                frmTemplate.Show vbModal
                Documents.Add strTemplate, False, 0, True
                strFileName = strLocation
                strId = GetID()
                'MsgBox strId
                strFooterText = CStr(Format(CInt(strId), "0000000")) _
                & "/" & strUser & "/" & strRequestee & "/" & strCaseRef & "/" & strDate
                'MsgBox strFooterText
                strFileName = strId & "_" & strRequestee & "_" & strCaseRef & "_" & strUser
                ActiveWindow.ActivePane.View.Type = wdPrintView
                ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
                Selection.TypeText strFooterText
                Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
                Selection.WholeStory
                With Selection.Font
                    .Name = "Arial"
                    .Size = 8
                End With
                ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
                Application.ChangeFileOpenDirectory strLocation
                ActiveDocument.SaveAs strFileName
            End If
        End If
    Else
        'look up template folder
        frmBasicTemplates.Show vbModal
        Documents.Add strTemplate, False, 0, True
    End If
    Application.ScreenUpdating = True
    Exit Sub
    ActiveDocument.Close False
End Sub

Open in new window

0
 

Expert Comment

by:RomAniA12
ID: 34238133
You have a bunch of error's in your code that renders it useless..
0
 
LVL 19

Accepted Solution

by:
MINDSUPERB earned 2000 total points
ID: 34238165
I suspect that your connection to the DB is not properly established. Check it out.

Try to change this line in 25: strId = GetID() into
strId = 1

Run the macro and see what happens.

Sincerely,
Ed
0
 
LVL 1

Author Comment

by:mccannit
ID: 34238169
ok.  the code worded fine in word 2003.  Any suggestions on how to make this work on Word 2007?
0
 
LVL 1

Author Comment

by:mccannit
ID: 34238249
That worked a treat MINDSUPERB.  Thank you very much for all your help.
0
 
LVL 1

Author Closing Comment

by:mccannit
ID: 34238258
Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Why do some people recommend buying business VoIP from an ISP? What are the benefits to my company? What are the costs?
Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

730 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