Adding References with code?

CALV

Registered User.
Local time
Today, 06:37
Joined
Apr 25, 2001
Messages
74
Hi all,

Just finishong of a dbase, which has a snapshot viewer control on one of the forms, works fine on my system, but when I try it on another system, the second line of code gives an error about mising references (the line is nothing to do with snapshot controls! its lbluser.caption=UCASE (username)
It turns out that the snapshot reference is marked as "MISSING", if I add this reference manually, all is well, the problem is, I dont want to have to do this on every system, is there a way to do this through code?

TIA

CALV
 
Thanks a lot, that looks just like what I need, I'll give it a try later on today.

CALV
 
Hi,

I managed to finally try this, the snag is, I get the error as soon as the form loads, I tried deleting ALL the code from the form_load, and replacing it with the code to set the references, but then I get the error on the line:

Set ref = References.AddFromFile(blah blah)


So the lack of the reference (in this case, snapshot viewer), stops me running just about ANY code, does anyone have any suggestions?

TIA

CALV
 
CALV,

I haven't seen a "higher level" product do this. We generally
used to lose references to Excel, Word and MS Project. Or they
used to "mysteriously" change version numbers. This code used
to fix it.

In this case, the lack of the snapshot viewer, should not
render the "Set ref = References.AddFromFile" unusable, which
is a VBA function.

The only thing that I can think of off hand is that (for some
versions of Access) there is a way to start the DB without
compiling the code. Then it would not look for the missing
references, but would still have enough "smarts" to load them.

I don't have Access on this machine, so I can't check not.

Keep me posted,
Wayne
 
Hi all,

Thanks for the replies, I seem to be making SLOW progress!, I read all of the articles, and I'm getting a little closer, hres the situation now:

I put the following code in to a function which is called by autoexec macro so it runs right away, and put the snapshot viewer ocx into a folder on C: called test


Function add_refs()
on error goto err_oops
Dim ref As Reference
Set ref = References.AddFromFile("C:\test\SNAPVIEW.ocx")
exit function
err_oops:
MsgBox (ErrorMsg)
End Function

Now, If I REMOVE the reference to the snapshot viewer manually, then run the database on one of the workstations which gives the problems, the above works fine! BUT, if I DONT manually remove the reference first, then I get a "runtime error 32813 name conflicts with an existing Module, Project, or Object Library" Now I assume this is because even thought the reference is marked as MISSING, its still sort of their, and so I cant add it again, so I tried to remove the reference initially using this code which I got from Microsofts site, I initially tried it as it is, referencing the callender control, copy/pasted right off the web page:

Function RemoveReference() As Boolean
Set ref = References!MSCAL
References.Remove ref
RemoveReference = True


Now this gives me a runtime error 9 Subscript out of range

See my idea was to REMOVE the reference, then add it again, thus eliminating my first problem of the name conflict.

Can anyone offer any more asistance?

TIA

CALV
 
Well, I fixed it!

Still doesnt work with the mscal, but works fine with snapshot viewer, turns out that you get "runtim error 9 subscript out of range" if the reference either cant be removed (dunno why this would be) or its ALREADY removed, bit of a stupid error IMO.
Anyway the following code works fine if anyones interested.

Function add_refs()
Dim ref As Access.Reference
Dim strname As String
Dim test As Integer
On Error GoTo oopsy


strname = "SnapshotViewerControl"
Set ref = Access.References(strname)
Access.References.Remove ref
Set ref = Nothing

err_must_have_removed: ' resumes here if get error so must have been removed already

'add the reference

Set ref = References.AddFromFile("G:\dbases\workdb\required_files\snapview.ocx")
Exit Function

'error trap
oopsy:
'Debug.Print Err.NUMBER, Err.Description
If Err = 9 Then Resume err_must_have_removed'
MsgBox Err.Description
End Function
 

Users who are viewing this thread

Back
Top Bottom