OberonPlace.com Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 13-10-2004, 13:55
rharpe
Guest
 
Posts: n/a
Default VB to control PrintMerge in Corel11

I am currently working on a project that will take information from a MS Access Database and 'Print Merge' into a Corel Draw 11 template that I designed. I need it to be automated so that the user(s) don't have to do anything but scan in a simple barcode and type in how many pages to print of each. This is what I'm envisioning:

The user(s) will open a VB form and barcode a ticket/customer barcode into the text field. The information will then created as a temporary db on the local computer, which will be the db that the print merge will use. (The reason for creating a temp db on the local machine is to avoid network traffic.) After the print merge takes place, it will then send the templates with the correct info attached, to a print queue.

If possible, I would like all of this to happen in the background where the user doesn't have to see it.

I have attempted to use macros, but it always shows up as, "This function is not available." (Or something to that effect.)

Any help would be greatly appreciated.



~rharpe
Reply With Quote
  #2  
Old 18-10-2004, 10:10
rharpe
Guest
 
Posts: n/a
Default

Does anybody know anything about Macro usage with Print Merge? Is it even possible?

Please, if someone could just answer, it would be greatly appreciated. Any links, or resources would be helpful too. I tried getting answers on the Corel website, but had no luck at all.

I found this forum on a newsgroup that corel provided.


~rharpe
Reply With Quote
  #3  
Old 18-10-2004, 11:30
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Well, the answer is yes and no. Unfortunately, PrintMerge itself isn't supported through VBA as of yet. However you can implement similar thing yourself. You can pull the data from a database (or a text file, whatever) with VBA and then look for text objects with particular text in them, or with particular object names and replace the content with that of the data field.

This way you will not reply on PrintMerge and can do the merge in the document itself, not while printing...

If this is something you are interested in, please provide more details on what the data is, how the document is laid out and what exactly you need to do, and I may be able to provide some code samples to help you get started...
Reply With Quote
  #4  
Old 18-10-2004, 13:28
rharpe
Guest
 
Posts: n/a
Default

Sounds good to me! Let me show you the steps I take:











I used colors to show the text that will be merged and where.


My table in my Access Database is really quite simple:
I use an Auto_ID number, Customer_ID, Customer_ID_Barcode, Name, Phone, and Fax... That's it so far.
Reply With Quote
  #5  
Old 18-10-2004, 21:14
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Ok, that's the kind of detail I'm talking about!

Here is piece of code to illustrate how this could be done. Create your template. Instead of placing merge fields, just create separate text objects and give them the names that correspond to field names in your database. Such as "Customer_ID", "Name", "Phone", etc. To specify an object name, use Object Manager docker, click on selected object node and you should enter the edit mode where you can specify the object name. Or alternatively you can open Object Data Manager docker and specify the object names in the Name field.

It doesn't matter at this point what text the objects contain. The actual text will be replaced with the database record values.

There is a problem with Barcode though. It is not possible to automate it directly. It is possible to hack it a bit and just invoke the OLE Server (Barcode Wizard) and then send the actual barcode data through keyboard simulation (using VBA's SendKeys command). It is somewhat easier to do in CorelDRAW 12 as it has some more support for OLE objects (can easily activate it, check if the server application is running and so on). In CorelDRAW 11, you'll have to use CorelScript.OLEObjectDoVerb command).

You can see some code examples on using CorelScript approach here:

http://www.oberonplace.com/forum/viewtopic.php?t=608
http://www.oberonplace.com/forum/viewtopic.php?t=212

Here is the code for CorelDRAW 12 which seems to work OK on my machine. Note that you need to add reference to "Microsoft ActiveX Data Objects" type library.

Code:
Sub SimulatePrintMerge()
    Dim doc As Document
    Dim bNewPage As Boolean
    
    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_Customer_Order_Form", cnn, _
        adOpenForwardOnly, adLockReadOnly
    
    Set doc = OpenDocument("C:\Temp\MergeTemplate.cdr")
    bNewPage = False
    
    While Not rs.EOF
        ProcessRecord doc, rs, bNewPage
        bNewPage = True
        rs.MoveNext
    Wend

    rs.Close
    cnn.Close
End Sub

Private Sub ProcessRecord(doc As Document, rs As ADODB.Recordset, ByVal bNewPage As Boolean)
    Dim s As Shape
    Dim fld As ADODB.Field
    
    If bNewPage Then
        doc.ActivePage.Shapes.All.Copy
        doc.AddPages 1
        doc.ActiveLayer.Paste
    End If
    
    For Each fld In rs.Fields
        If fld.Name = "Customer_ID_Barcode" Then
            ' Find the Barcode OLE object
            Set s = doc.ActivePage.FindShape(Type:=cdrOLEObjectShape)
        Else
            ' Find the object by name
            Set s = doc.ActivePage.FindShape(fld.Name)
        End If
        
        If Not s Is Nothing Then
            If s.Type = cdrTextShape Then
                ' Text fields
                s.Text.Story = fld.Value
            ElseIf s.Type = cdrOLEObjectShape Then
                ' Barcode
                s.OLE.Activate
                DoEvents
                SendKeys fld.Value, True
                SendKeys "{ENTER}{ENTER}{ENTER}", True
                While s.OLE.IsServerRunning
                    DoEvents
                Wend
            End If
        End If
    Next fld
End Sub
I hope this gives you some ideas.

P.S. I'm attaching my version of MergeTemplate.cdr. Note, I just threw in some text objects and the barcode object on the page. Didn't even try to align them or so any fancy formatting. It still should give you some ideas on how it's done. I'm also attaching my sample Access database in case yours doesn't work with my code for some reason.
Attached Files
File Type: cdr MergeTemplate.cdr (15.0 KB, 620 views)
File Type: zip CustomerScan.zip (8.1 KB, 608 views)
Reply With Quote
  #6  
Old 19-10-2004, 09:57
rharpe
Guest
 
Posts: n/a
Default Thank you!

Thank you so much for helping me out. I haven't got it working yet, but I'll let you know if I'm successful. As for the barcode, I just use a font called "3 of 9 barcode" in True Type. As long as I have the '*' enclosing the alphanumeric item, it works fine. Do you think the '*' could cause a problem in the code?

Anyways, I better go try it out. I'll be back.


~rharpe
Reply With Quote
  #7  
Old 19-10-2004, 13:50
rharpe
Guest
 
Posts: n/a
Default Ok, this is where I'm at...

For a while I was getting this "macros are disabled..." bit, but then I was able to stop it from coming up. Now I get this error and it stops at this part of the code... not really sure why, could be incompatible with CorelDraw11?


Any ideas?
Reply With Quote
  #8  
Old 19-10-2004, 13:59
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: Ok, this is where I'm at...

Yes, as I said in my previous post, the example I specified was for CorelDRAW 12. In Draw 11 you'll have to use CorelScript to simulate some of the functionality:

Quote:
Originally Posted by Alex
There is a problem with Barcode though. It is not possible to automate it directly. It is possible to hack it a bit and just invoke the OLE Server (Barcode Wizard) and then send the actual barcode data through keyboard simulation (using VBA's SendKeys command). It is somewhat easier to do in CorelDRAW 12 as it has some more support for OLE objects (can easily activate it, check if the server application is running and so on). In CorelDRAW 11, you'll have to use CorelScript.OLEObjectDoVerb command).
Reply With Quote
  #9  
Old 19-10-2004, 14:10
rharpe
Guest
 
Posts: n/a
Default

Oops, I missed that part. I'll go ahead and try it to see if I can get it to work. What do you think about the last thing I said regarding a different font. Wouldn't that be easier?
Reply With Quote
  #10  
Old 19-10-2004, 14:30
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

I don't know about faking barcodes with fonts. It might work. I don't have much experience with barcodes in the first place. So I'll leave it for you to try it out
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 10:24
CorelDRAW 10/11 VBA - dialog control MrClark CorelDRAW/Corel DESIGNER VBA 2 06-03-2003 21:18


All times are GMT -5. The time now is 20:14.


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