Advertisement

05.15.2008 at 09:12AM PDT, ID: 23405759
[x]
Attachment Details

macro stops after closing the active document

Asked by BAJ05 in VB Script, Visual Basic Programming, Microsoft Word

Tags: microsoft, visual basic/ MS word, all, esp. 2007

I have a Word form that I want to upload to a database after filling it out. This process is done through a VB macro. The MYSQL DB connection is done through ADODB. When I want to upload the file the file has to be closed. I have the macro in a template that I have open during the execution and the form is referencing the macro from the template. This was working in 2003 but now people start using MS Word 2007 and then when the active document closes the execution of the macro stops even when the template is still open.
here is some of the code:

 ActiveDocument.SaveAs FileName:=strNewDocName
 ActiveDocument.Close

  'Create connection to database
 Set conn = New ADODB.Connection
 conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=yyy;DATABASE=table;UID=xxx;PWD=xxx;OPTION=16427"

  conn.CursorLocation = adUseClient
  conn.Open
   
   
  Set rs = New ADODB.Recordset
  Set mystream = New ADODB.Stream
  mystream.Type = adTypeBinary
  rs.Open "SELECT * FROM log WHERE 1=0", conn, adOpenStatic, adLockOptimistic
  rs.AddNew
  mystream.Open
  mystream.LoadFromFile strNewDocName
       
  ' Upload data to database
  rs!user = Application.UserName
  rs!Date = mydate & mytime
  rs!status = status
  rs!moduleTested = strDocName
  rs!project = project
  rs!Document = mystream.Read
  ' need to translate "\n" into something else...
  rs!Comments = comment
  rs!operating_system = os
  rs.Update
  mystream.Close
  rs.Close
  conn.Close


Please let me know if you need more information.

Thanks for the kind help

Bernd
Start Free Trial
[+][-]05.15.2008 at 10:43PM PDT, ID: 21580265

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 06:30AM PDT, ID: 21582476

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.18.2008 at 05:24PM PDT, ID: 21594609

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: VB Script, Visual Basic Programming, Microsoft Word
Tags: microsoft, visual basic/ MS word, all, esp. 2007
Sign Up Now!
Solution Provided By: bigjokey
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628