I'm working through the Learning Microstation VBA book. I'm trying to connect an element to an external database so that I can assign information to it for reporting later.
The code in the text is this:
Function CreateDatabaseLink(Mslink As Long, Entity As Long, DatabaseType As MsdDatabaseLinkage, IsInformation As Boolean, DisplayableAttributeType As Long) As DatabaseLink
End Function
Sub DatabaseLinkA()
Dim myElem As Element Dim myLink As DatabaseLink Set myElem = CommandState.GetLocatedElement(True) Set myLink = CreateDatabaseLink(1, 1, msdDatabaseLinkageOleDb, True, 0) myElem.AddDatabaseLink myLink myElem.Rewrite
End Sub
with the exception that I have replaced "LinkType" in the book with "DatabaseType" - although the results are the same either way.
In both cases, I have an element selected in the drawing, and when I run DatabaseLinkA(), Microstation crashes.
Any idea what's going on?
Layne
Unknown said:CreateDatabaseLink(1, 1, msdDatabaseLinkageOleDb, True, 0)
That tells VBA to create an MSLink having link ID 1 and entity ID 1.
The entity ID is the numeric ID of a table in your database MSCatalog table. If that table doesn't exist, you must create it.
Read more about MicroStation VBA and databases.
Regards, Jon Summers LA Solutions
Layne Olivo
Settings->Database->Setup shows that it is connected
I've tried to attach the error log.exception.log
As it happens, I can actually write to the database from VBA...
Hi Bruce,
Unknown said:I believe you must have an active database connection for things like this to work
I thought the same, but suprisingly the connected database is not required. From MicroStation VBA help file: In fact, these operations are function even MicroStation does not have a relational database attached.
At least it makes the situation easier as we can expect the problem doesn't exist because of not connected DB ;-)
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point