Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set References in an mde at runtime. 1

Status
Not open for further replies.

Stewartp

Programmer
Jan 31, 2003
5
GB
I have an Access database that imports Outlook contacts.
However some of the machines the program will be installed
on do not have outlook. Thus the reference to MSOUTL.OLB
(Microsoft Outloook 10 object library) is "Missing". I can
check to see if Outlook is installed and which version it
is. I need to either add a reference or delete it during
runtime depending on whether Outlook is installed. I am using the following code which works fine in
the development environment as an mdb but gives the following error as an mde file:

ERROR
40179: Requested type library or wizard is not a VBA project

CODE
Function ReferenceFromFile(strFileName As String) As
Boolean
Dim Ref As Reference

On Error GoTo Error_ReferenceFromFile
' Create new reference.
Set Ref = References.AddFromFile(strFileName)
ReferenceFromFile = True

Exit_ReferenceFromFile:
Exit Function

And

Function RemoveReference(strName As String) As Boolean

Dim Outref As Access.Reference

On Error GoTo Error_ReferenceFromFile
' Remove reference.
Set Outref = Access.References(strName)
Access.References.Remove Outref
Set Outref = Nothing
RemoveReference = True

Exit_RemoveReference:
Exit Function





during runtime as an .mde file on the target machine the following error occurs.

ERROR
-2147319779: Method 'Item of object'_References' failed.

Does anyone have any suggestions?

Thanks

Stewart
 
I have about the same problem. I'm just trying to call a public sub from the On_Load event of a form. The problem first showed it's head when i was using the AutoExec macro to call the public sub. I always used to work, and i never made any changed to the code.

My computer was getting slow, so i formatted,and reinstalled Win2k with sp2, Office 2k with sp 1 and 2.
This is when the problem started.


it's difficult to tell what specifically it's complaining about.
 
Hi Stewartp,

As far as I know you can't change References in an MDE file.

Copied from Access Help:
========================================
About MDE files
If your database contains Microsoft Visual Basic code, saving your Microsoft Access database as an MDE compiles all modules, removes all editable source code, and compacts the destination database. Your Visual Basic code will continue to run, but it cannot be viewed or edited, and the size of your Access database will be reduced due to the removal of the code. Additionally, memory usage is optimized, which will improve performance.

Saving your Access database as an MDE file prevents the following actions:

Viewing, modifying, or creating forms, reports, or modules in Design view.

Adding, deleting, or changing references to object libraries or databases.

Changing code using the properties or methods of the Microsoft Access or VBA Object models — an MDE file contains no source code.
========================================

I know this would be a pain and probably stating the obvious, but you could produce 2 versions of your DB before creating the MDE's, Outlook Installed and Not Installed versions.

Bill
 
I also remember MDE can't change the references.

But...why do you need a reference to Outlook?

It works just fine without the reference set. However, you have to dim the objects as Variant or Object, not as Outlook.Application, Outlook.TaskItem, Outlook.MailItem and so on.

If Outlook is not installed, CreateObject will fail, but the error is trappable.

Advantage: no need to check Outlook version
Disadvantage: you lose the 'magic dot' and have to use numbers instead of Outlook built-in constants: 0 instead of olMailItem.

HTH


[pipe]
Daniel Vlas
Systems Consultant

 
I have since found the trick is to use Late Binding rather than Early Binding.
Here is the code that works a treat! I have marked the Binding methods so you can see the two side by side. By trapping the 429 error we can see if Outlook is installed on the target machine and proceed accordingly.

Dim olapp As Object '(Late binding)
'Dim olapp As Outlook.Application (Early Binding)
Dim nspNameSpace As Object 'Outlook.NameSpace
Dim fldContacts As Object 'Outlook.MAPIFolder
Dim objContacts As Object
Dim objContact As Object
Dim strZLS As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strAddress As Variant
Dim R As Variant
Dim intProgress As Integer

Const ERR_APP_NOTFOUND As Long = 429

On Error GoTo GetAll_Err
' Initialize zero-length string variable
' used in the Restrict method argument.
strZLS = ""
' Get reference to the Outlook Contacts folder.
'Set olapp = New Outlook.Application (Early binding)
Set olapp = CreateObject("Outlook.Application") ' (Late Binding)
Set nspNameSpace = olapp.GetNamespace("MAPI")
Set fldContacts = nspNameSpace.GetDefaultFolder(10) 'olFolderContacts = 10
Set objContacts = fldContacts.Items.Restrict(&quot;[FullName] <> '&quot; & strZLS & &quot;'&quot;)

Thanks for everyones help...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top