Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

Weird one - Application.CurrentProject.Path not returning correct path?

I have an MS Access 2000 application which uses a call to

Application.CurrentProject.Path


When I run the MS Access application on my machine it works just fine and returns the correct path.



However, when I deploy the MDB to another machine.....somehow.....I don't know how......it is retaining the application path from MY machine....instead of using the new one on the current machine!!!!

How could the path get embedded inside my application like that?
Avatar of stevbe
stevbe

that is truely bizarre ... is there any issues with MISSING references? have you repaired/compact recently, does everything compile OK?

Steve
Avatar of Tom Knowlton

ASKER

I've run compact and repair and compiled  **just before** distributing the app......same problem.
To see the problem for yourself:

http://www.robotzgame.com/inven_updates/dload.htm

the link at the very top of the page is the one you want.
just for testing .... does CurrentDb.Name tell you the correct location?

Steve
>>>ust for testing .... does CurrentDb.Name tell you the correct location?

Let me check that....it'll take me a few minutes...
hey tom ... if you have picture links it will always try to find them as soon as the form loads ... even into design mode ... so you need to set the picture property for all of your image controls to = "" before deploying. You will need to do this through code because otherwise Access will think you no longer want to display a picture and delete the image control on you, just like you can't make a lable with no text.

Steve
Hmmmmm....okay.

This has nothing to do with my Image   PictureType property being set to Linked   vs.   Embedded?????


I will try doing what you recommended.
By the way....I just noticed that the error message is coming up exactly 6 times.

This is the same number of Image controls on the form.......a very INTERESTING coincidence........LOL.......
absolutley has everything to do with Linked images :-)
You say it DOES have something to do with LINKED images?

So LINKED means the Image object is retaining the last known path to the image?
I tried adding in the following code into my Main Form's ONLOAD event:

 Me.ImageCostumeItemAssignedPicture.Picture = ""
    Me.ImagePreviewCostumeImage.Picture = ""
    Me.ImagePreviewPropsImage.Picture = ""
    Me.ImagePropsItemAssignedPicture.Picture = ""
    Me.ImageSearchByPlayCostumePicturePreview.Picture = ""
    Me.ImageSearchByPlayPropPicturePreview.Picture = ""

The same problem still happens when I deploy the MDB to another machine.
compacting and repairing the MDB on the machine I am deploying to also does nothing to prevent the problem.

The path to MY originating folder is embedded somewhere inside the MDB......
It seems that whatever is happening is happening before the Form OnLoad(   )   event is invoked......
So LINKED means the Image object is retaining the last known path to the image?

Yes

I made a function that you need to run BEFORE deploying. Make sure the form is closed first. The code opens the form in design mode, changes the Picture poerty to "" and saves the form.

Public Function CleanUp()

Dim aob As AccessObject
Dim frm As Access.Form

    For Each aob In CurrentProject.AllForms
        DoCmd.OpenForm aob.Name, acDesign
        Set frm = Forms(aob.Name)
        If frm.Name = "FormMain"
            frm.ImageCostumeItemAssignedPicture.Picture = ""
            frm.ImagePreviewCostumeImage.Picture = ""
            frm.ImagePreviewPropsImage.Picture = ""
            frm.ImagePropsItemAssignedPicture.Picture = ""
            frm.ImageSearchByPlayCostumePicturePreview.Picture = ""
            frm.ImageSearchByPlayPropPicturePreview.Picture = ""
            DoCmd.Close acForm, frm.Name, acSaveYes
        End If
    Next

End Function

Steve
Getting a syntax error when comiling the code after pasting in your function:

If frm.Name = "FormMain"


says syntax error
Oh.....forgot the THEN:

Public Function CleanUp()

Dim aob As AccessObject
Dim frm As Access.Form

    For Each aob In CurrentProject.AllForms
        DoCmd.OpenForm aob.Name, acDesign
        Set frm = Forms(aob.Name)
        If frm.Name = "FormMain" Then
            frm.ImageCostumeItemAssignedPicture.Picture = ""
            frm.ImagePreviewCostumeImage.Picture = ""
            frm.ImagePreviewPropsImage.Picture = ""
            frm.ImagePropsItemAssignedPicture.Picture = ""
            frm.ImageSearchByPlayCostumePicturePreview.Picture = ""
            frm.ImageSearchByPlayPropPicturePreview.Picture = ""
            DoCmd.Close acForm, frm.Name, acSaveYes
        End If
    Next

End Function
ASKER CERTIFIED SOLUTION
Avatar of stevbe
stevbe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Steve:

Let me say 2 things:

1)  THANK YOU....your solution works great.

2)  This is really HOKEY to have to do this!!!  It works....but seems like kind of a kludge.
So if I call this Function on FORM CLOSE........would that be a reliable way to deploy and not have to remember to run this function every time?

I'll test this.....
yup ... but if you ask MS ... "works as designed"
I look at these kind of things as exceptions and as long as I can work around them I thnk it is ok (notice ok is lower case) because they did so many other things well.
Running the code in the close event depends on your target audience ... if you are deploying to runtime only client this code will not work for them so I would say test using no code (I'm not sure it will save what you set) and then test using your code in the Close event.

Steve
Thanks.