Book a Demo

Author Topic: Connecting w VBA - Error - "Object variable or With block variable not set"  (Read 6611 times)

filipepinto

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Hi,

I'm trying to connect to a MS-SQL instance using VBA (from within MS-Word) but I'm getting the error "Object variable or With block variable not set".

This is the code that I'm using:

Code: [Select]

Sub GetSparxElements()
'
' Returns the list of elements from a Repository
'
'

[code]Dim Repository As EA.Repository
Dim ConnectString As String

ConnectString = "SPARX --- DBType=1;Connect=Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SPARX;Data Source=X-CPROD270;LazyLoad=1;"
bool = Repository.OpenFile(ConnectString)

End Sub

Rings a bell?

Thanks!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
You'll need to create the Repository object before you can use it.

Should look something like this:
Code: [Select]
Set Repository = new EA.Repository()

filipepinto

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Hey Simon,

Thank you for your answer.

I'm using VBA. Doesn't the Dim instantiates the variable?

Code: [Select]
Dim Repository As EA.Repository
Thanks

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
No. It only defines the space (or more specific the reference) for the object.

q.
« Last Edit: February 08, 2017, 09:22:20 am by qwerty »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
I'm far from an expert at VBA, but your although the error message is typically cryptic it interpreted as the need to create the object.

http://sparxsystems.com/enterprise_architect_user_guide/13.0/automation/setup.html

The VB6 instructions use a Dim with New.

filipepinto

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Thanks Simon - that solved it! ;D