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:Dim myElem As Element ... myElem.Rewrite
If you step through your code (F8), do you see where it's failing?
Put some Debug.Assert and Debug.Print statements in there to monitor what's happening. For example...
Debug.Assert Not myElement Is Nothing
Put an error reporter in there to trap run-time problems. For example...
Sub DatabaseLinkA () On Error Goto err_DatabaseLinkA ... Exit Sub err_DatabaseLinkA: ReportError "DatabaseLinkA" End Sub Public Sub ReportError (ByVal procName As String) MsgBox "Error " & CStr (err.Number) & ": " & err.Description & vbNewLine & _ "Was caused by " & err.Source, vbOk Or vbExclamation, "Error in " & procName End Sub
Regards, Jon Summers LA Solutions