Code written for Access 2002 fails in 2003`

T

tpcolson

The code pasted below was written by a now "not working with us"
developer to display a series of pictures in a multipage form. Some
background: The form is used to record information about ecological
surveys, which involve counting lots of trees. For each survey site, 3
pictures are taken and the images are given a unique name, XXXXXXA.jpg,
XXXXXXE.jpg, and XXXXXXN.jpg, for a picture of the site, a picture
north of the site, and a picture east of the site. The VB code would
display the appropriate picture in the appropriate box on the form, and
the forms were filtered on the site unique identifier. I'd like to
emphasize strongly that this worked PERFECTLY in Access 2002. No bugs,
no crashes, worked great for 18 months.

Then we upgraded the lab to Office 2003.

As soon as the form is opened..the following error appears: "Run time
error '2753': A problem occured while microsoft access was
communicating with the OLE server or Active X control."

Running debugger highlights the following line:

Me.Image_a.Action = acOLECreateLink

In the 2002 version of this, the following reference were "checked":
Visual Basic for Apps
MS Access 10.0 object library
MS Active X Data Objects 2.1 Library
MS Office XP Web components
OLE Automation.

In the 2003 version the only difference is the MS Access 10.0 Object
Library is now the MS Access 11.0 Object Library.

I tried replacing the 11.0 Library with the 10.O library, same error.
I've set macro security to none. I've held a feather over my head and
chanted buddhist prayers. No one around here could write 10 lines of VB
code to save their lives. This IS an academic lab.....

The path of all the db files and pictures has not changed, as this is
all on the same, orginal machine.

I'm thinking the error here is incompatibility with object libraries.
Two questions here...what do I have to check to make this work, and why
do new releases of MS software break everything developed with older
versions?


Option Compare Database
Dim strPath As String

Private Sub Form_Current()
'If there is an image name in the record then set the source file to
the
'file path of the image. If there is no picture, set the file path to
the
'path of the NoPicture.jpg image which is a blank picture. Do this for
each
'of the three image objects.

If Not IsNull(Me.Picture_a.Value) Or Trim(Me.Picture_a.Value) > "" Then
Me.Image_a.SourceDoc = strPath + "pictures\" + Me.Picture_a.Value
Me.Image_a.Action = acOLECreateLink
Else
Me.Image_a.SourceDoc = strPath + "pictures\NoPicture.jpg"
Me.Image_a.Action = acOLECreateLink
End If
If Not IsNull(Me.Picture_n.Value) Or Trim(Me.Picture_n.Value) > "" Then
Me.Image_e.SourceDoc = strPath + "pictures\" + Me.Picture_e.Value
Me.Image_e.Action = acOLECreateLink
Else
Me.Image_e.SourceDoc = strPath + "pictures\NoPicture.jpg"
Me.Image_e.Action = acOLECreateLink
End If
If Not IsNull(Me.Picture_e.Value) Or Trim(Me.Picture_e.Value) > "" Then
Me.Image_n.SourceDoc = strPath + "pictures\" + Me.Picture_n.Value
Me.Image_n.Action = acOLECreateLink
Else
Me.Image_n.SourceDoc = strPath + "pictures\NoPicture.jpg"
Me.Image_n.Action = acOLECreateLink
End If
End Sub

Private Sub Form_Load()
Dim cn As ADODB.Connection
Dim i As Integer
Dim intpos As Integer

'Set connection to current database
Set cn = CurrentProject.AccessConnection

'Gets full path for current database including file name
strPath = cn.Properties("Data Source")

'Gets position of last slash
For i = 1 To Len(strPath)
If Mid(strPath, i, 1) = "\" Then
intpos = i
End If
Next i

'Strips file name off full path
strPath = Mid(strPath, 1, intpos)
'Closes connection
cn.Close
Set cn = Nothing

End Sub
 
G

Guest

I was intrigued by the subject line of your post and decided to check it out.
I have not read the entire thing in detail, but would suggest the following:

1. Make sure you have all appropriate service packs and updates for
Windows, Access (Office), and the Jet databasae engine.

2. Go to the list of references, make a note of the order of the checked
references. Then browse the list and if there is another one down in the
list with the same name but a higher version number, Uncheck the old one and
THEN Check the new one.

3. Remember that when you change references in this way, you will need to
close the reference dialog, then reopen it and REORDER the checked references
in the same order as before you started.

I am not an expert or an MVP, and I wish I could be more specific to help
you avoid frustration, but I hope this helps.

Bill
 
G

Guest

This is what i found:
acOLECreateLink -- Creates a linked OLE object from the contents of a file.
To use this setting, you must first set the control's OLETypeAllowed and
SourceDoc properties. Set the OLETypeAllowed property to acOLELinked or
acOLEEither. The SourceDoc property specifies the file used to create the OLE
object. You can also set the control's SourceItem property (for example, to
specify a row-and-column range if the object you're creating is a Microsoft
Excel worksheet). When you create an OLE object by using this setting, the
control displays a metafile graphic image of the file specified by the
control's SourceDoc property. If you save the OLE object, only the link
information, such as the name of the application that supplied the object and
the name of the linked file, is saved because the control contains an image
of the data but no source data.

so it looks like you might try setting the OLETypeAllowed = acOLELinked

Sub Command1_Click
OLE1.Class = "Excel.Sheet" ' Set class name.
' Specify type of object.
OLE1.OLETypeAllowed = acOLELinked
' Specify source file.
OLE1.SourceDoc = "C:\Excel\Oletext.xls"
---i dont think u need this part---
' Specify data to create link to.
OLE1.SourceItem = "R1C1:R5C5"
---
' Create linked object.
OLE1.Action = acOLECreateLink
--- or this part ---
' Adjust control size.
OLE1.SizeMode = acOLESizeZoom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top