Drawing from an Access database

Drawing from an Access database

Anonymous
Not applicable
155 Views
4 Replies
Message 1 of 5

Drawing from an Access database

Anonymous
Not applicable
Has anyone ever tried to read from an Access Database much like you
would from an Excel spreadsheet? What I am trying to do I can now do
from Excel, but would like to pull from the source. The goal is to
read position data about objects into a drawing file and insert a block
at the position that is recorded in the database. Please forgive my
ignorance, I haven't given much effort to this yet, but am doing a
little bit of research first. Here is the code that I have been using
from Excel, this example just draws lines.

Thanks,
Rob

' Allows the user to establish a starting point for the lines to be
drawn
objStartPoint = ThisDrawing.Utility.GetPoint(, vbCr & " Pick a point
to start from: ")

' Determines the ROW to start on
RowNum = 2

' Excel file linkning and opening
Set ExcelApp = CreateObject("Excel.Application")

ExcelApp.Workbooks.Open
FileName:="D:\MFVR\Year_Two\Collection_Verification\test.xls"

Set ExcelDoc = ExcelApp.ActiveWorkbook
Set ExcelSheet = ExcelDoc.ActiveSheet

While ExcelSheet.cells(RowNum, 2).Value <> ""
varDirection = Trim(ExcelSheet.cells(RowNum, 2).Value)
dblDirection = ThisDrawing.Utility.AngleToReal(varDirection,
acDegrees)
varDistance = Trim(ExcelSheet.cells(RowNum, 3).Value)

objPolarPoint =
ThisDrawing.Utility.PolarPoint(objStartPoint, dblDirection, varDistance)

Set objLine = ThisDrawing.ModelSpace.AddLine(objStartPoint,
objPolarPoint)
objStartPoint = objPolarPoint

RowNum = RowNum + 1
Wend

ZoomExtents
ExcelApp.Application.Quit

----------------------------------------
Robert B. Brown
Lead Visualization Specialist
703.923.4496
----------------------------------------
Autometric Inc.
http://www.autometric.com
0 Likes
156 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
I use DAO to read Access databases. It is terrific. Supposedly the new
wavw is to use ADO but my experience with DAO has been so good that it is
hard to switch. Reference the DAO3.51 libraries in the VBA editor and
browse it using the object browser. The help files will get you started
with examples.
good luck,
-mjm
Robert Brown wrote in message <3843EE66.7BF2DE7A@autometric.com>...
>Has anyone ever tried to read from an Access Database much like you
>would from an Excel spreadsheet? What I am trying to do I can now do
>from Excel, but would like to pull from the source. The goal is to
>read position data about objects into a drawing file and insert a block
>at the position that is recorded in the database. Please forgive my
>ignorance, I haven't given much effort to this yet, but am doing a
>little bit of research first. Here is the code that I have been using
>from Excel, this example just draws lines.
>
>Thanks,
>Rob
>
>' Allows the user to establish a starting point for the lines to be
>drawn
> objStartPoint = ThisDrawing.Utility.GetPoint(, vbCr & " Pick a point
>to start from: ")
>
>' Determines the ROW to start on
> RowNum = 2
>
>' Excel file linkning and opening
> Set ExcelApp = CreateObject("Excel.Application")
>
> ExcelApp.Workbooks.Open
>FileName:="D:\MFVR\Year_Two\Collection_Verification\test.xls"
>
> Set ExcelDoc = ExcelApp.ActiveWorkbook
> Set ExcelSheet = ExcelDoc.ActiveSheet
>
> While ExcelSheet.cells(RowNum, 2).Value <> ""
> varDirection = Trim(ExcelSheet.cells(RowNum, 2).Value)
> dblDirection = ThisDrawing.Utility.AngleToReal(varDirection,
>acDegrees)
> varDistance = Trim(ExcelSheet.cells(RowNum, 3).Value)
>
> objPolarPoint =
>ThisDrawing.Utility.PolarPoint(objStartPoint, dblDirection, varDistance)
>
> Set objLine = ThisDrawing.ModelSpace.AddLine(objStartPoint,
>objPolarPoint)
> objStartPoint = objPolarPoint
>
> RowNum = RowNum + 1
> Wend
>
> ZoomExtents
> ExcelApp.Application.Quit
>
>----------------------------------------
>Robert B. Brown
>Lead Visualization Specialist
>703.923.4496
>----------------------------------------
>Autometric Inc.
>http://www.autometric.com
>
>
0 Likes
Message 3 of 5

Anonymous
Not applicable
Robert,
I have used information from Access databases in a couple of
programs. Its really an easy way to get your data. The following is some
code to get you started.

Dim dbsSlipon As Database
Dim rstSlipon As Recordset
Set dbsSlipon = OpenDatabase("y:\databases\Flange.mdb")
Dim sqlStatement As String
Dim strTablename As String
strTablename = "300"

sqlStatement = "SELECT * FROM " & strTablename & " WHERE [Size] = " &
cboSize.Text

Set rstSlipon = dbsSlipon.OpenRecordset(sqlStatement)

dblFlangeheight = rstWeld![Weld Flange Height]
dblRaisedthk = 0.0625
dblHubbasedia = rstSlipon![Hub Base Dia]
dblHubdia = dblHubbasedia
dblFacethk = rstSlipon![Flange Thk]
dblFacedia = rstSlipon![Flange Dia]
dblRaiseddia = rstSlipon![Raised Face Dia]
dblFlangeheight = rstSlipon![Slipon Flange Height]
dblPipedia = rstSlipon![Pipe Dia]
dblBoltcircledia = rstSlipon![Bolt Circle Dia]

--Adam Thomas
Assistant Systems Coordinator
Chattanooga Boiler and Tank Co.
AThomas@cbtank.com
0 Likes
Message 4 of 5

Anonymous
Not applicable
Sorry, the Table name should be
strTablename = "tblSlipon"
0 Likes
Message 5 of 5

Anonymous
Not applicable
My experience with Excel and Acces (or DAO):

Getting information from an Excel worksheet to a 2Darray variable:
20 rows and 7 columns took 4 seconds (before the form appears I'm using)
80 rows and 7 columns took 10 sec.

Using a database-file made in Acces:
20 rows and 7 colums took about 1 sec.
160 rows and 7 columns took about 1 sec.

A reason for not using Excel again in cases where much data is needed.

Greetings,
Henk
0 Likes