OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #21  
Old 02-11-2004, 20:40
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Oh, I think I understand the problem you mentioned about the macro quitting before it completes.

It appears your template CDR file has a VBA project embedded into it (even though it has no macro). When loading the file under CorelDRAW 11, VBA environment gets reset and all running macros are aborted.

To fix the problem, open the CDR file in CorelDRAW, then save it back and while doing this, remove a checkmark from "Save with embedded VBA Project" box in the Save dialog.

This should help.
Reply With Quote
  #22  
Old 03-11-2004, 10:22
rharpe
Guest
 
Posts: n/a
Default

I think my document may be going corrupt. This comes up after double clicking on the file from the "c:\temp\" directory???


After clicking "OK" to that message this other one pops up after I select Corel down on the status bar:


It's funny, because I installed Corel Draw 11 at home and everything worked fine. But, another thing while I was at home, I noticed my file I saved on my server space had no macros when I opened it. It asked me if I wanted to run macros, be safe, etc. and I said yes... still no macros. Oh well, I just copied the code you provided and it worked.

I added a instant print function too:

Code:
Sub MergeDataRecords()
    Dim doc As Document
   
    Dim cnn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim s As String
   
    ' Open the connection to the database file
    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=C:\Temp\CustomerScan.mdb"

    rs.Open "SELECT * FROM ttemp", cnn, _
        adOpenForwardOnly, adLockReadOnly
   
   
    While Not rs.EOF
        Set doc = OpenDocument("C:\Temp\Customer_Forms.cdr")
        ProcessRecord doc, rs
        ' do something to the completed document - save, or print, whatever...
        '...
        MsgBox "Document processed"
        ' Now just close this document and repeat for the other records
        doc.Close
        rs.MoveNext
    Wend

    rs.Close
    cnn.Close
End Sub

Private Sub ProcessRecord(doc As Document, rs As ADODB.Recordset)
    Dim p As Page
    Dim s As Shape
    Dim fld As ADODB.Field
   
    ' Loop through available pages and process them in turn
    For Each p In doc.Pages
        For Each fld In rs.Fields
            ' Find the object by name
            Set s = p.FindShape(fld.Name)
           
            If Not s Is Nothing Then
                If s.Type = cdrTextShape Then
                    ' Text fields
                    s.Text.Story = fld.Value
                End If
            End If
        Next fld
    Next p
End Sub
In the code on line 19 you said to put a function:
Code:
' do something to the completed document - save, or print, whatever...
        '...
So I put:
Code:
Application.ActiveDocument.PrintOut
Which works great...at home. :wink:
Reply With Quote
  #23  
Old 03-11-2004, 12:17
rharpe
Guest
 
Posts: n/a
Default

UPDATE!

OK, my intentions were to make this thing so simple a monkey could do it... no more! I've had it with these GlobalMacro issues that keep killing my Corel program. I decided to leave some steps so that the user could actually use their brain, just a little.

The steps I've decided to teach to the user:
1)Open the fBarcode_Input under the Forms Objects
2)Type in/Barcode the number needed for entry
3)Click the "Run A VBA Macro" button (what looks like a "universal play button")
4)Have a message box prompt the user to either print or not.
5)Shutdown and start over again.

I'm assuming, once the user has done this a few times, it should be second nature. :wink:

Alex, I appreciate all the help you have done. I have only one more question: Are you an original designer for Corel Draw? You seem to know ALOT regarding this program!

Just wondering.
Reply With Quote
  #24  
Old 05-01-2005, 10:22
rharpe
Guest
 
Posts: n/a
Default Happy New Year to All!

Hey everyone!

I am now working full throttle with this code, (provided generously from Alex,) which is awsome.

I wish there was a way to modify the actual macro from VB Access Form. Right now I have to open the Corel file, modify the macro, build it, save it, then run it. Is it possible for me to run an VB Form and choose my printing settings? The code below can explain better:
Code:
Sub MergeDataRecords()
    Dim doc As Document
   
    Dim cnn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim s As String
    Dim i As Integer 'for counter loop
    
    ' Open the connection to the database file
    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=C:\smm\smm00_lt.mdb"

    rs.Open "SELECT * FROM ttemp_Corel_Order_Forms", cnn, _
        adOpenForwardOnly, adLockReadOnly
   
   
    While Not rs.EOF
        Set doc = OpenDocument("C:\smm\orderforms\Customer_Forms.cdr")
        ProcessRecord doc, rs
                
        'do something to the completed document - Print...
        yes = MsgBox("Are you sure you want to print 5 copies of each order form?", vbYesNo)
            If yes = vbYes Then

                ' Printing 5 copies of the Standard Lavatory Form
                With ActiveDocument.PrintSettings
                    .PageRange = "1"
                    .Copies = 5
                End With
                Application.ActiveDocument.PrintOut

                ' Printing 5 copies of the Custom Lavatory Form
                With ActiveDocument.PrintSettings
                    .PageRange = "2"
                    .Copies = 5
                End With
                Application.ActiveDocument.PrintOut

                ' Printing 5 copies of the Standard Shower Form
                With ActiveDocument.PrintSettings
                   .PageRange = "3"
                   .Copies = 5
                End With
                Application.ActiveDocument.PrintOut

                ' Printing 5 copies of the Custom Shower Form
                With ActiveDocument.PrintSettings
                   .PageRange = "4"
                   .Copies = 5
                End With
                Application.ActiveDocument.PrintOut

                ' Printing 5 copies of the Tub Deck/Slab Form
                With ActiveDocument.PrintSettings
                  .PageRange = "5"
                  .Copies = 5
                End With
                Application.ActiveDocument.PrintOut

                ' Printing 5 copies of the Accessories & Trim Form
                With ActiveDocument.PrintSettings
                  .PageRange = "6"
                  .Copies = 5
                End With
                Application.ActiveDocument.PrintOut


             Else
            'MsgBox "The print job has been cancelled!", vbCritical
            'Now just close this document and repeat for the other records
            End If
        doc.Close
        rs.MoveNext
    Wend

    rs.Close
    cnn.Close
End Sub

Private Sub ProcessRecord(doc As Document, rs As ADODB.Recordset)
    Dim p As Page
    Dim s As Shape
    Dim fld As ADODB.Field
   
    ' Loop through available pages and process them in turn
    For Each p In doc.Pages
        For Each fld In rs.Fields
            ' Find the object by name
            Set s = p.FindShape(fld.Name)
           
            If Not s Is Nothing Then
                If s.Type = cdrTextShape Then
                    ' Text fields
                    s.Text.Story = fld.Value
                End If
            End If
        Next fld
    Next p
End Sub
It's currently set at 5 copies per page. How hard would it be to change this from an external VB Form?
Reply With Quote
  #25  
Old 05-01-2005, 22:57
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: Happy New Year to All!

Have you considered doing the whole thing in Access? I mean, put all that VB code in your Access database right where your form is. Access has almost the same VBA as CorelDRAW does. You can create a program (macro) in CorelDRAW which will control MS Access and vice versa.

If nothing else, you can still pass some parameters to your VBA macro in CorelDRAW.

You can write a (let's say) text file from your Access macro and have VBA macro read it in. You can put the value in system registry somewhere, or even create a separate Access table and put the value there, so you can read it in from VBA.

I'm not sure how you launch the CorelDRAW macro from Access. Do you use GMSManager.RunMacro method or you ask the user to go to CorelDRAW and start the macro?

If you use RunMacro method, you can actually pass parameters:

Code:
Public Sub MergeDataRecords(ByVal NumCopies As Long)
...
End Sub
in your Access code:

Code:
drawapp.GMSManager.RunMacro "YourGMSFile", "Module1.MergeDataRecords", 5
This should work...

I hope this gives you some ideas...
Reply With Quote
  #26  
Old 11-01-2005, 11:50
rharpe
Guest
 
Posts: n/a
Default

Thanks Alex! It does give me some more ideas. The problem is, I don't know much about the registry, therefore a little timid when working with it.

Right now, the user calls up an order for, let's say, a catalog. Once the customer is brought up on the screen the "ID", "Name", "Phone" and "Fax" are sent to a temporary table that is used as a storage for Corel to look at. Then Corel loads up with the correct form. You must manually run the macro for it to mailmerge and then be sent to the printer. Like I complained about before, the number of copies need to be changed on a constant basis. (Some people order multiple catalogs, some only one.)

Maybe I'll setup an option in Corel? I'll have to think about it.

Thanks again for your ideas, I'll consider them.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MCI Control: Unknown! Cinzy CorelDRAW/Corel DESIGNER VBA 1 12-05-2003 09:24
CorelDRAW 10/11 VBA - dialog control MrClark CorelDRAW/Corel DESIGNER VBA 2 06-03-2003 20:18


All times are GMT -5. The time now is 09:29.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com