if I can get a pointer with objptr

  • Thread starter Thread starter asc4john
  • Start date Start date
A

asc4john

If I can get a pointer with objptr. Why can't I go the other way.

dim cll as Collection
dimcll2 as Collection
dim ptr as long

ptr = ObjPtr(cll) '
but set cll2 = ptr ERROR

I am not asking to do this
Set SomeWierdNonCollectionThingy = ptr
 
If I can get a pointer with objptr. Why can't I go the other way.

dim cll as Collection
dimcll2 as Collection
dim ptr as long

ptr = ObjPtr(cll) '
but set cll2 = ptr ERROR

I am not asking to do this
Set SomeWierdNonCollectionThingy = ptr

Why not just:

set cl2 = cl1

???
 
I want to pass that "pointer" to another form. Using openargs and
passing a string, then using Me.Tag to pass back a string has become
very clumsy. Since OpenArgs is actually a variant there must be a
better way. Altough I can set one global collection and pass thru that
I would rather just pass a pointer around.
 
I want to pass that "pointer" to another form. Using openargs and
passing a string, then using Me.Tag to pass back a string has become
very clumsy. Since OpenArgs is actually a variant there must be a
better way. Altough I can set one global collection and pass thru that
I would rather just pass a pointer around.

I think it was Bill Gates himself who decided that VB and VBA would
not support pointers ... the "ObjPtr" thing was a kludge invented to
provide a work-around for the limitations (at the time) of the COM
object model.

Every variant has a subtype ... internally, a variant in VBA is
implemented as a C union. I can't point you to a reference for this,
but I believe it is adequately documented somewhere (others: please
feel free to pitch in with links!) Therefore, it is not possible to
simply assign one variant to another without some intermedient
"compiler magic" (or interpreter magic, in the case of VBA).

Have you considered custom database properties? Check out the help
file topic for the Properties collection and the Property attribute.

If we grant that you could somehow do what you propose (i.e. using
pointers), and you would be doing it as indicated by your short
example code, then you would need to consider the lifetime of the
object you are passing around. It looks to me like you NEED to have a
global object (because after you leave the procedure where you have
defined the Collection object, its lifetime would be undefined).
 
Using a golbal variable seems to work quite well so I'll go with it.
It has also allowed a solution to an other problem. Also is there a way
to know if a form has been open as a dialog with DoCmd.openForm
"frmName, acNormal,,,,acDialog?
 
Back
Top