Domanda

Im currently creating an app in Microsoft Access that references the "Reflections for regis graphics" library. Bascially the below code will create a new instance of reflections which is an external telnet app that connects to a host system at work. From there I can pass vba commands to it so I can automate some steps within the telnet app.

Dim RIS as object
Set RIS as New Reflection4.session
RIS.visible = True
With RIS
   ...do some stuff
end with

The above works fine, the problem is when I use other modules or procedures in my program I cannot seem to get VBA to point to the existing object that is already created if I have more than one open.

eg I may have an existing telnet session open that Im doing some of my usual work in, then I run my VBA app, which will then try to create its own session to work in. The VBA code below...

Set RIS = GetObject(, "reflection4.session")

...doesnt seem to be smart enough to figure out which telnet window its supposed to look at. From what I can tell it just latches on to the first one created. Which is why I always have to make sure that any existing telnet sessions are closed before running any of my automated VBA apps, which is a pain.

The getobject command above takes in a [pathname] and a [class] as its two inputs. So what I have working so far is pathname = blank and class = "reflection4.session"

Is there a way to either create new Reflection4.session with pointers or names so I can reference them later or use getobject in another way so I can find the actual session I really need so I can keep my other telnet sessions open without disturbing them? Would I have to loop through some sort of object collection and find the newest one???

È stato utile?

Soluzione

If you only need to find sessions you've created in your own code, you could just track the sessions in your own Collection.

'in a module
Global RefSessions as New Collection

'when you're creating
Dim RIS As Reflection4.session
Dim cKey as String

Set RIS as New Reflection4.session
RIS.visible = True
With RIS
   '...do some stuff
End with

cKey = "SomeUniqueIdentifier"
RefSessions.Add RIS, cKey

'when you're using it later, instead of GetObject
Set RIS = RefSessions("SomeUniqueIdentifier")
With RIS
   '...do other stuff
End With

'...or...
Set RIS = RefSessions(2)
With RIS
   '...do other stuff
End With

'...or...
For Each RIS in RefSessions 'loop through every session object added
    With RIS
        '...do other stuff
    End With
Next RIS
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top