Results 1 to 38 of 38

Thread: Word doc

  1. #1

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353

    Resolved Word doc

    From VB I shell a word doc, for user entry! When they close the doc, is there a way to capture what the user adds to the doc for the database?
    Last edited by mudfish; Oct 1st, 2004 at 12:25 PM.
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    Silly question buy why are you using a Word Doc for user entry? Wouldn't it be easier to create the form in VB and link it to a database?
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  3. #3

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    Yes it would but the boss would like me to do it like this! I can put data in it, but out I do not know how I would do it! I have also lost control once I shell it!
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Try this for starters.
    VB Code:
    1. Option Explicit
    2. 'Add a reference to MS Word xx.0 Object Library
    3. Private moApp As Word.Application
    4. Private moDoc As Word.Document
    5.  
    6. Private Sub cmdOpenDoc_Click()
    7.     Set moDoc = moApp.Documents.Open("D:\Development\MyDoc.doc")
    8. End Sub
    9.  
    10. Private Sub Form_Load()
    11.     Set moApp = New Word.Application
    12.     moApp.Visible = True
    13. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    That all most the same code I use to start the doc!
    Code:
        Call WordMain
        LoadDocument "FillText40", strPct_of_Time_Overflow                         '' pg3 Pct of Time_Overflow
        objWord.ActiveDocument.Protect wdAllowOnlyFormFields
        objWord.Visible = True
    So how can I tell when they close the doc?
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    You need to create either a WithEvents event to intercept the
    Document_Close event or if you are using the same document all
    the time you can add a module and a class module to take full
    control of Words events. I have to go to client site right now, but
    if no one can help by the time I get back, I will help you more.

    Oh ya, search in code bank for my Excel Event demo. Its the basis
    for what you want but in Excel.

    Later.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    Thank I found it! I think I will have more ??? so I am not checking the thread off!
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  8. #8

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    RobDog888

    This code would go in excel?

    "
    Option Explicit

    Private RD As clsMyEvents
    "

    I am using a .dot for this project!
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    No, the logic is what you want to replicate in Word. I just got
    back from the Clients site and I am going to lunch. Be back with
    an example after lunch.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    I am east coast!
    It is near quitting time here.

    Will a macro have to go into my system?

    Thank for the help!
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I got the demo attached for you, but because of the immediatness
    of the request, I only had time to do it in Word. If you need to
    use VB to simulate the same thing let me know.

    VB Code:
    1. 'ThisDocument
    2. Option Explicit
    3.  
    4. Private RD As clsMyEvents
    5.  
    6. Private Sub Document_Open()
    7.     Set RD = New clsMyEvents
    8.     MsgBox "My Events Created!", vbOKOnly + vbInformation, "My Word Events"
    9. End Sub
    10.  
    11.  
    12. 'Name: clsMyEvents
    13. 'Instancing: Private
    14. Option Explicit
    15.  
    16. Public goWord As Word.Application
    17.  
    18. Public WithEvents MyEventsDoc As Word.Document
    19. Public WithEvents MyEventsApp  As Word.Application
    20.  
    21. Private Sub Class_Initialize()
    22.     Set goWord = GetObject(, "Word.Application")
    23.     Set MyEventsDoc = ThisDocument
    24.     Set MyEventsApp = goWord
    25. End Sub
    26.  
    27. Private Sub Class_Terminate()
    28.     Set goWord = Nothing
    29. End Sub
    30.  
    31. Private Sub MyEventsApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
    32.     Dim iResp As Integer
    33.     iResp = MsgBox("RobDog888: Do you want to save your document?", vbYesNoCancel + vbQuestion, "My Word Events")
    34.     If iResp = vbYes Then
    35.         goWord.ActiveDocument.Save
    36.         If goWord.ActiveDocument.Saved = True Then
    37.             MsgBox "Saved!", vbOKOnly + vbInformation, "My Word Events"
    38.         Else
    39.             MsgBox "Error Saving Document!" & vbNewLine & "Sorry!", vbOKOnly + vbCritical, "My Word Events"
    40.         End If
    41.     ElseIf iResp = vbCancel Then
    42.         Cancel = True
    43.     End If
    44. End Sub
    VB/Outlook Guru!

    Attached Files Attached Files
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353

    At home, had to see the code!
    Take some time!
    My work day was over.
    I am not set up at home to run what I was working on.
    Thank for the help!

    PS We run preloaded machines and push code down our lines!
    That why I ask for about a macro!
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  13. #13

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353

    Fire wall will not let me download!
    I am working in VB 6.5!

    This code is on a form?
    "
    'ThisDocument
    Option Explicit

    Private RD As clsMyEvents

    Private Sub Document_Open()
    Set RD = New clsMyEvents
    MsgBox "My Events Created!", vbOKOnly + vbInformation, "My Word Events"
    End Sub

    "
    Should have got the download from the house!




    Compile error
    User-defined type not defined

    On

    Private RD As clsMyEvents

    I have the word reference in the project
    Last edited by mudfish; Sep 29th, 2004 at 07:16 AM.
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Its behind the word document (VBA).
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    Can I get this to work out of VB to a .dot?
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    What is the way you hope to have this working?
    [list=1][*]From VB only[*]From Word only[*]From VB and Word Template[/list=1]
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    Originally posted by RobDog888
    What is the way you hope to have this working?
    From VB and Word Template
    I have a VB form that I am filling a listbox with name from the database. User picks a name and I fill the dot with data from the database and shell the dot. The user can fill in some fields in the dot and print it. They want me to be able to shell it blank, let user fill in and save it back to the database. I am working on doing it in VBA. We have a large area network that our machines are preloaded with the VB package, so we can just transmit code down our lines. So if I add code to the dot I can just transmit it down the line with the code.

    This should work; the code in VBA is attached to the dot, right?

    I have your word doc got to the code change it some, but I do not see the changes on the word doc. How do I compile in VBA?
    Last edited by mudfish; Sep 30th, 2004 at 08:11 AM.
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I think the only version of Office VBA that had a compiler was
    Office XP Developer. I always had problems creating and trapping
    events in Word from VB, but I can give it another try later today.
    One of the problems was when the user had more than one
    instance of wrod running.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    Yes I can see that been a problem.
    They have pull me off for right now, but there is always tomorrow!

    Thanks for the input!
    I got in your code on the word doc and change the message, but I do not see it changing.
    I see a huge script in it also.
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Did you try the document attachment in my post that shows the code?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  21. #21

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    Yes I got in your code on the word doc and change the closing message, but I do not see the message changing when I would close the doc?

    I also see a huge VS script in the word doc also.

    Thanks again
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  22. #22
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    You changed the message in this line?
    VB Code:
    1. iResp = MsgBox("RobDog888: Do you want to save your document?", vbYesNoCancel + vbQuestion, "My Word Events")
    You shouldnt see any more code in the word doc module (ThisDocument)
    and class file (clsMyEvents) than what I posted earlier.


    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  23. #23

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    Yes
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  24. #24
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    You close the document and save the changes? Then when you
    open the document, the welcome message is still the same or
    when you close the document at this point still should the original message?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  25. #25

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    I was looking for it at close.

    When I try and run it in the VBA like I would in VB it wants me to name and create a macro, I think! It is not in front of me, at home!
    I have 6.5 VB, C++ 6 XP office Pro and .Net studio.
    Last edited by mudfish; Sep 30th, 2004 at 08:23 PM.
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  26. #26
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Does the code reflect the change the next time you open the doc?
    Maybe it was stuck in memory or the vba code was in run mode?

    What is the cange you want in the close message?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  27. #27

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    I add some number to "45456RobDog888: Do you want to save your document".
    But I am only getting "Do you want to save your document".

    I wish I had it here, I also have SQL enterprise manager, XP network and Multi-edit.
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  28. #28
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Ah! I think its not running the custome msgbox. If the title of the
    close msgbox does not say "My Word Events" then it is the Word
    msgbox and not ours firing.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  29. #29

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    It like this "MyWordEvents", like the doc name!
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  30. #30
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Oh ya, check to make sure that you have Macros enabled when
    word starts. Set the marco security to medium so you can choose
    the setting each time Word starts. I get the feeling that its not
    runing.

    Edit: the save msgbox title should be exactly - "My Word Events"
    if its running. Not the document name.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  31. #31

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    It late here 5:30 come fast.
    I try at work.
    Thanks.
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  32. #32
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Ok, see you tomorrow. Its 7:00 pm here.

    Later
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  33. #33

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    7:30 am at work change the marco security and it works.
    I still get the word save message.


    Can I use SQL in the word project like ADO just like in VB?

    Thanks again.

    PS this is out of script editor
    "
    <html xmlns="urn:schemas-microsoft-comfficeffice"
    xmlns:w="urn:schemas-microsoft-comffice:word"
    xmlns="http://www.w3.org/TR/REC-html40">

    <head>
    <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
    <meta name=ProgId content=Word.Document>
    <meta name=Generator content="Microsoft Word 10">
    <meta name=Originator content="Microsoft Word 10">
    <link rel=File-List href="MyWordEvents_files/filelist.xml">
    <link rel=Edit-Time-Data href="MyWordEvents_files/editdata.mso">
    <title>My Word Events Demo</title>
    <!--[if gte mso 9]><xml>
    <oocumentProperties>
    <o:Subject>Word Automation</o:Subject>
    <o:Author>RobDog888</o:Author>
    <o:LastAuthor>ckupfer</o:LastAuthor>
    <o:Revision>9</o:Revision>
    <o:TotalTime>6</o:TotalTime>
    <o:Created>2004-09-30T12:04:00Z</o:Created>
    <o:LastSaved>2004-09-30T12:16:00Z</o:LastSaved>
    <o:Pages>1</o:Pages>
    <o:Words>1</o:Words>
    <o:Characters>6</o:Characters>
    <o:Company>Advanced Program Solutions</o:Company>
    <o:Lines>1</o:Lines>
    <o:Paragraphs>1</o:Paragraphs>
    <o:CharactersWithSpaces>6</o:CharactersWithSpaces>
    <o:Version>10.3501</o:Version>
    </oocumentProperties>
    </xml><![endif]--><!--[if gte mso 9]><xml>
    <w:WordDocument>
    <w:View>Print</w:View>
    <w:Compatibility>
    <w:BreakWrappedTables/>
    <w:SnapToGridInCell/>
    <w:WrapTextWithPunct/>
    <w:UseAsianBreakRules/>
    <w:UseFELayout/>
    </w:Compatibility>
    <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
    </w:WordDocument>
    </xml><![endif]-->
    <style>
    <!--
    /* Font Definitions */
    @font-face
    {font-family:PMingLiU;
    panose-1:2 1 6 1 0 1 1 1 1 1;
    mso-font-alt:\65B0\7D30\660E\9AD4;
    mso-font-charset:136;
    mso-generic-font-family:auto;
    mso-font-formatther;
    mso-font-pitch:variable;
    mso-font-signature:1 134742016 16 0 1048576 0;}
    @font-face
    {font-family:"\@PMingLiU";
    panose-1:0 0 0 0 0 0 0 0 0 0;
    mso-font-charset:136;
    mso-generic-font-family:auto;
    mso-font-formatther;
    mso-font-pitch:variable;
    mso-font-signature:1 134742016 16 0 1048576 0;}
    /* Style Definitions */
    p.MsoNormal, li.MsoNormal, div.MsoNormal
    {mso-style-parent:"";
    margin:0in;
    margin-bottom:.0001pt;
    mso-pagination:widow-orphan;
    font-size:12.0pt;
    font-family:"Times New Roman";
    mso-fareast-font-family:PMingLiU;
    mso-fareast-language:ZH-TW;}
    @page Section1
    {size:8.5in 11.0in;
    margin:1.0in 1.25in 1.0in 1.25in;
    mso-header-margin:.5in;
    mso-footer-margin:.5in;
    mso-paper-source:0;}
    div.Section1
    {page:Section1;}
    -->
    </style>
    <!--[if gte mso 10]>
    <style>
    /* Style Definitions */
    table.MsoNormalTable
    {mso-style-name:"Table Normal";
    mso-tstyle-rowband-size:0;
    mso-tstyle-colband-size:0;
    mso-style-noshow:yes;
    mso-style-parent:"";
    mso-padding-alt:0in 5.4pt 0in 5.4pt;
    mso-para-margin:0in;
    mso-para-margin-bottom:.0001pt;
    mso-pagination:widow-orphan;
    font-size:10.0pt;
    font-family:"Times New Roman";}
    </style>
    <![endif]-->
    </head>

    <body lang=EN-US style='tab-interval:.5in'>

    <div class=Section1>

    <p class=MsoNormal>456est</p>

    </div>

    </body>

    </html>
    "
    Last edited by mudfish; Oct 1st, 2004 at 06:39 AM.
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  34. #34
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    You say you still get the Word save message meaning that
    you are not getting the custom save message?

    You mean that you want the project to be in Words VBA and you
    want to know if you can use SQL in there then the answer is yes,
    I think so. I havent tried it but it should be possible.

    Let me know.

    Its 9:00 am over here now. I just got in.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  35. #35

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    Originally posted by RobDog888
    You say you still get the Word save message meaning that
    you are not getting the custom save message?

    I am get 2 custom and 1 word message! If I do not save.
    If I save I get 3 custom.

    So you think ADO will work?
    Last edited by mudfish; Oct 1st, 2004 at 11:27 AM.
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  36. #36
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I just had to see if I could make you a example using ADO and SQL.
    So here it is.

    Note this is separate from the other document and not inclusive
    of what we have done earlier.

    VB Code:
    1. Option Explicit
    2. 'RobDog888 10/01/2004
    3. 'ThisDocument
    4. 'Add reference to MS ActiveX Data Objects 2.x Library
    5. 'Tools > References ...
    6. Private Sub Document_Open()
    7.     'Initialize SQL connection and objects
    8.     Main
    9.     Stop
    10.     'Command1_Click
    11. End Sub
    12.  
    13. Private Sub Command1_Click()
    14.  
    15.     On Error GoTo No_Bugs
    16.    
    17.     Dim oRs As ADODB.Recordset
    18.  
    19.     Set oRs = New ADODB.Recordset
    20.     Set oRs = goEnv.SQLTie.QrySQLTable("FindMe")
    21.     If oRs.BOF = False And oRs.EOF = False Then
    22.         'Do something with the recordset
    23.         Do While oRs.EOF = False
    24.             '...
    25.             '...
    26.             '...
    27.             oRs.MoveNext
    28.         Loop
    29.     Else
    30.         MsgBox "No Records Returned!", vbOKOnly + vbExclamation, "RobDog888 - Command1_Click"
    31.     End If
    32.     If oRs.State = adStateOpen Then oRs.Close
    33.     Set oRs = Nothing
    34.     Exit Sub
    35.    
    36. No_Bugs:
    37.     MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation, "RobDog999 - Command1_Click"
    38. End Sub
    39.  
    40. '********************************************************************************************************
    41.  
    42. Option Explicit
    43. 'RobDog888 10/01/2004
    44. 'Module: modMain
    45. Public goEnv                     As clsEnv
    46.  
    47. Public Sub Main()
    48.  
    49.     Set goEnv = New clsEnv
    50.     'Change the server and database names to yours
    51.     If goEnv.DBConnect("\\ServerName\DatabaseName") = False Then
    52.         MsgBox "Failed to connect to database!" & vbNewLine & _
    53.         "Please contact an Administrator to check if you have the appropriate permissions.", _
    54.         vbExclamation + vbOKOnly, "RobDog888 - Main"
    55.         Set goEnv = Nothing
    56.     Else
    57.         MsgBox "Connected to SQL Database!", vbOKOnly + vbInformation, "RobDog888 - Main"
    58.     End If
    59.  
    60. End Sub
    61.  
    62. '********************************************************************************************************
    63.  
    64. Option Explicit
    65. 'RobDog888 10/01/2004
    66. 'Class: clsEnv
    67. 'Instancing: Private
    68. Private moCnn As ADODB.Connection
    69. Private moSQLTie As clsSQL
    70.  
    71. Public Property Get Cnn() As ADODB.Connection
    72.     Set Cnn = moCnn
    73. End Property
    74.  
    75. Public Property Get SQLTie() As clsSQL
    76.     Set SQLTie = moSQLTie
    77. End Property
    78.  
    79. Public Function DBConnect(ByVal sDBPath As String) As Boolean
    80.  
    81.     On Error GoTo No_Bugs
    82.  
    83.     Dim sDB As String
    84.     Dim sSQL As String
    85.    
    86.     sDB = InStrRev(sDBPath, "\")
    87.     sSQL = Mid(sDBPath, 1, sDB - 1)
    88.     sDB = Mid(sDBPath, sDB + 1)
    89.     sSQL = Mid(sSQL, 3)
    90.     If moCnn.State = adStateClosed Then
    91.         moCnn.ConnectionString = "provider=sqloledb;data source=" & sSQL & ";initial catalog=" & sDB & _
    92.         ";integrated security=sspi;"
    93.         'Add "integrated security=sspi"
    94.         moCnn.Open
    95.         DBConnect = True
    96.     Else
    97.         moCnn.Close
    98.         moCnn.ConnectionString = "provider=sqloledb;data source=" & sSQL & ";initial catalog=" & sDB & _
    99.         ";integrated security=sspi;"
    100.         moCnn.Open
    101.         DBConnect = True
    102.     End If
    103.     Exit Function
    104.  
    105. No_Bugs:
    106.  
    107.     If Err.Number = "-2147467259" Then
    108.         MsgBox "Error connecting to database!", vbOKOnly + vbCritical, "RobDog888 - DBConnect"
    109.     Else
    110.         MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbInformation, "RobDog888 - DBConnect"
    111.     End If
    112.     DBConnect = False
    113.     Exit Function
    114.     Resume
    115. End Function
    116.  
    117. Private Sub Class_Initialize()
    118.     Set moCnn = New ADODB.Connection
    119.     Set moSQLTie = New clsSQL
    120. End Sub
    121.  
    122. Private Sub Class_Terminate()
    123.     Set moCnn = Nothing
    124.     Set moSQLTie = Nothing
    125. End Sub
    126.  
    127.  
    128. '********************************************************************************************************
    129.  
    130. Option Explicit
    131. 'RobDog888 10/01/2004
    132. 'Class: clsSQL
    133. 'Instancing: Private
    134. Public Function QrySQLTable(ByVal sAction As String) As ADODB.Recordset
    135.  
    136.     On Error GoTo No_Bugs
    137.  
    138.     Dim oRs As New ADODB.Recordset
    139.     Dim sSQL As String
    140.  
    141.     sSQL = "SELECT"
    142.     sSQL = sSQL & " Field1,"
    143.     sSQL = sSQL & " Field2,"
    144.     sSQL = sSQL & " Field3"
    145.     sSQL = sSQL & " FROM"
    146.     sSQL = sSQL & " Table1"
    147.     sSQL = sSQL & " WHERE"
    148.     sSQL = sSQL & " Field1 = '" & sAction & "'"
    149.    
    150.     Set oRs = New ADODB.Recordset
    151.     oRs.Open sSQL, goEnv.Cnn, adOpenKeyset, adLockOptimistic, adCmdText
    152.     Set QrySQLTable = oRs
    153.     Set oRs = Nothing
    154.     Exit Function
    155.    
    156. No_Bugs:
    157.     MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbInformation, "RobDog888 - QrySQLTable"
    158. End Function
    VB/Outlook Guru!

    Attached Files Attached Files
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  37. #37

    Thread Starter
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    Great!
    Soon as I am allowed to work on the program again, I will try it!

    Thanks again.
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  38. #38
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    No prob.

    Later.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width