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 11-11-2003, 20:12
diwin
Guest
 
Posts: n/a
Default connection string - access database

I can code well in vba from within access.
I can connect an ASP web page to an access database in VBScript.
But I don't know how to code a connection to an Access database from in CorelDraw 11. ADO? DAO? Not sure. All attempts fail miserably.

Anyone here know? :?

CorelDraw11 (with VBA 6.3)
Windows XP Pro
MS Access 2000
Reply With Quote
  #2  
Old 11-11-2003, 20:42
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: connection string - access database

VBA like most other languages doesn't have database access natively supported, however it is based on COM and ActiveX and can consume almost any COM component installed on your system. You can use ADO, DAO or any other database component from VBA in CorelDRAW just as you do in ASP's VBScript or from Access. Add a reference to, say, ADO type library (Tools>References), and go from there.
Reply With Quote
  #3  
Old 23-11-2003, 20:52
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Working Example

I had never tried this before, so I thought I would give it a go. Here is what I came up with.

First in the VBA window make sure you go to: Tools: References and add the "Microsoft ActiveX Data Objects 2.x Library"

Once you have done that you are set. Here is my sample code:

Code:
Sub TestAccessConn()

Dim objConn As New ADODB.Connection
Dim objRS As New ADODB.Recordset

Dim i As Long
Dim x As Double, y As Double, r As Double
Dim n As Long
Dim MaxX As Double, MaxY As Double, MaxR As Double
Dim s As Shape

objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\sample.MDB;"
objConn.Open
   
objConnState = objConn.State
If objConnState = 1 Then
    MsgBox "The connection to this database is working!", vbInformation
Else
    MsgBox "You were unable to connect to the database!", vbInformation
End If

objRS.Open "Select * FROM tblShapes", objConn, adOpenKeyset, adLockOptimistic

MaxX = ActivePage.SizeWidth
MaxY = ActivePage.SizeHeight
MaxR = 1

While Not objRS.EOF

For i = 1 To objRS("Number")

x = Rnd() * MaxX
y = Rnd() * MaxY
r = Rnd() * MaxR

Set s = ActiveLayer.CreateEllipse2(x, y, r)
s.Fill.ApplyUniformFill ActivePalette.Color(objRS("Color"))

Next i

objRS.MoveNext
Wend

objRS.Close
objConn.Close

Set objRS = Nothing
Set objConn = Nothing

End Sub
I have attatched the database for the example. Basically the code reads the database and creates several ellipises based on the records it reads. Hope this helps.

Shelby
Attached Files
File Type: zip sample.zip (6.9 KB, 779 views)
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
Create Catalog from database like MSWord??? diwin CorelDRAW/Corel DESIGNER VBA 5 06-04-2011 07:26
Need help connecting to database and filling combo box CamWest CorelDRAW/Corel DESIGNER VBA 6 22-12-2004 14:30
files import graphicdesigner CorelDRAW/Corel DESIGNER VBA 11 20-11-2004 00:56
how can we get string from... olympiatr CorelDRAW/Corel DESIGNER VBA 2 04-11-2004 03:39
Printing Raw Prn Files Mark Code Critique 2 16-09-2004 17:15


All times are GMT -5. The time now is 15:07.


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