Page 1 of 3 123 LastLast
Results 1 to 15 of 42
  1. #1
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MODULE TROUBLE (Access2000)

    Hey Guys, I got the code attached, from the web and have changed it to apply to my case. I
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: MODULE TROUBLE (Access2000)

    It's a little hard to tell what your problem is based on somebody else's sample code. You're sure the template exists, but does it exist where the code is trying to find it? Does the folder "C:WindowsApplication DataMicrosoftTemplates" actually exist on your machine? Why are you using "CLASSI~1.dot" if the template name is classic? You only need the short file name if the name is longer than 8 characters.
    Charlotte

  3. #3
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MODULE TROUBLE (Access2000)

    I am VERY sure the template is in that folder. When I checked the name in the property it appeared as CLASSI~1.dot, I've also tried Classic.dot but the same message appears.

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: MODULE TROUBLE (Access2000)

    Hi,
    It seems to me that that code is wrong - it's supposed to accept a registry section as an argument not a directory name. The code commented out above it looks like the correct sort of code (though you may need to change the section name according to your software versions)
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: MODULE TROUBLE (Access2000)

    GetPrivateProfileString is supposed to work with a file path as well as a registry key. I haven't tried it that way, but the help file says it's possible.
    Charlotte

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: MODULE TROUBLE (Access2000)

    Hi Charlotte,
    It's true that System.PrivateProfileString (is that a built-in shortcut for GetPrivateProfileString?) will work with a file path if you're pointing it at a settings file rather than the registry, but as far as I can remember (I don't have the module in question in front of me here) the point of the code as written was to retrieve the templates path. Princess is specifying the path to the template not to a settings file.
    Princess, I don't think there's any need for PrivateProfileString at all, unless this is going to be a distributed application and the path to that template may be different on each machine, in which case you will need to revise your code to look in the registry for the relevant section, or use the simpler Options.DefaultFilePath(wdUserTemplatesPath). Otherwise, you can just use:
    strTemplatePath = "C:WindowsApplication DataMicrosoftTemplates"
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MODULE TROUBLE (Access2000)

    I removed this code from the module:
    strDocsPath = objWord.System.PrivateProfileString("", _
    HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVe rsionExplorerShell Folders", _
    Personal") & ""
    Debug.Print "Docs path: " & strDocsPath
    But it still is displaying the error message on line:
    strTemplatePath = objWord.System.PrivateProfileString("", _
    "C:WindowsApplication DataMicrosoftTemplates", _
    "") & ""
    strWordTemplate = strTemplatePath & "ClassicTemp"
    Error message is:
    strTestFile = Nz(Dir(strWordTemplate))
    If strTestFile = "" Then
    MsgBox strWordTemplate & " template not found; can't create letter"
    Exit Sub
    End If
    What am I doing wrong?

  8. #8
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: MODULE TROUBLE (Access2000)

    Hi,
    Sorry, I obviously wasn't entirely clear - the bit you removed was fine, it's the
    strTemplatePath = objWord.System.PrivateProfileString("", _
    "C:WindowsApplication DataMicrosoftTemplates", _
    "") & ""
    bit you need to remove and replace with
    strTemplatePath = "C:WindowsApplication DataMicrosoftTemplates"
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  9. #9
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MODULE TROUBLE (Access2000)

    So thats now this:
    strTemplatePath = "C:WindowsApplication DataMicrosoftTemplates"
    strWordTemplate = strTemplatePath & "Classic.dot"

    But why does it still gives me an error message? this time:
    Error No: 5; Description: Invalid procedure, call or argument

  10. #10
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: MODULE TROUBLE (Access2000)

    Have you tried stepping through your code to see where exactly the error is occurring?
    Regards,
    Rory

    Microsoft MVP - Excel

  11. #11
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MODULE TROUBLE (Access2000)

    How do I step through the code Rory?
    This part of the code is outputting the error message:
    cmdWordInvoice_ClickError:
    MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
    Resume cmdWordInvoice_ClickExit

  12. #12
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: MODULE TROUBLE (Access2000)

    Click somewhere within your procedure in the VBEditor and press f8 to enter Step Into mode. Then press f8 repeatedly to step through each line of code. You are interested in the line of code that sends you into the error handler routine. It may be easier to comment out your On Error Goto statement(s) and run the procedure - the de###### should send you to the line of code that causes the error.
    Regards,
    Rory

    Microsoft MVP - Excel

  13. #13
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MODULE TROUBLE (Access2000)

    When I was on this line the error message was displayed:
    MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
    Resume cmdWordInvoice_ClickExit
    What does that mean? Is that supposed to display that error message or the error message was an error?
    <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  14. #14
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: MODULE TROUBLE (Access2000)

    That's your error handler - when any part of your code causes an error, the process jumps to the error handler and that (as you guessed) displays a message box saying that an error has occurred. Unfortunately, it doesn't tell you where exactly the error happened. I'd suggest commenting out the On Error Goto statements in your code (just type an apostrophe in front of them) and then running it. When the error occurs, a messagebox should appear asking if you want to debug. Choose Yes and it should highlight the line that is actually causing the error.
    Regards,
    Rory

    Microsoft MVP - Excel

  15. #15
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MODULE TROUBLE (Access2000)

    The following is the line I've commented:
    'On Error GoTo cmdWordInvoice_ClickError
    When I did run the code after commenting that line, it didn't display any error messages but it opened about 15 copies of the template and printed all data on one page.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •