Article View: adobe.scripting.indesign
Article #20758Re: Access Database
From: Ben Dupre
Date: Wed, 05 Jun 2002 15:21
Date: Wed, 05 Jun 2002 15:21
49 lines
2674 bytes
2674 bytes
Okay,
Once you dig deep enough to figure out how to open a database and execute an sql queery (easy stuff for most programmers) getting data from Access really isn't that hard. In case anyone is interested here is the sample script I cobbled together to figure out how to get data and place it in ID.
Being a newbie, however, I seem to have been tripped up by what should be a very stupid problem. There's something BASIC I don't understand here (couldn't resist the tired pun, sorry). Anyway, in the code below I'm having a problem because
1. The database has some field values as Null and I can't assign Null to a TextField. So I test for null right?
2. VB always evaluates the statement myRecordSet.Fields(j).Value <> Null as false. What is wrong with my comparison?
Ben
Dim DB As Connection
Dim myRecordSet As Recordset
Dim j As Integer
Dim Doc As InDesign.Document
Dim myPage As InDesign.Page
Dim ID As InDesign.Application
Dim Item As InDesign.TextFrame
Set ID = CreateObject("InDesign.Application.2.0")
Set Doc = ID.Documents.Add
Set myPage = Doc.Pages.Item(1)
Set DB = New Connection
DB.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51; Data Source=C:\Program Files\Microsoft Visual Studio\VB98\BIBLIO.MDB;"
Set myRecordSet = New Recordset
myRecordSet.Open "select Name,[Company Name],Address,City,State,Zip,Telephone from Publishers", DB, adOpenForwardOnly, adLockReadOnly
Debug.Print myRecordSet.RecordCount
Do While Not myRecordSet.EOF
If myRecordSet.BOF Then
myRecordSet.MoveNext
End If
For j = 0 To 6
Set Item = myPage.TextFrames.Add If myRecordSet.Fields(j).Value <> Null Then
Item.TextContents = CStr(myRecordSet.Fields(j).Value)
End If
Item.GeometricBounds = Array(40 + j * 10, 40, 50 + j * 10, 170)
Next j
Set myPage = Doc.Pages.Add
Loop
Technical Details
Message-ID:
<ef8d1e0.15@WebX.aaQKaf7vad4>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-02!supernews.com!peer.news.opaltelecom.net!newsfeed.wirehub.nl!news000.worldonline.se!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebXReferences:
<ef8d1e0.-1@WebX.aaQKaf7vad4>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,575c492b1935dbd8 X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2002-06-05 08:43:50 PST From: "Ben Dupre" <bdupre@sauer-danfoss.com> Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-02!supernews.com!peer.news.opaltelecom.net!newsfeed.wirehub.nl!news000.worldonline.se!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: Re: Access Database Message-ID: <ef8d1e0.15@WebX.aaQKaf7vad4> Date: Wed, 5 Jun 2002 08:21:29 -0700 References: <ef8d1e0.-1@WebX.aaQKaf7vad4> Lines: 57 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit