UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
2 Pages V  1 2 >  (Go to first unread post)
   Reply to this topicStart new topic
> Full Path To A Field On A Form, Access 2003    
 
   
ghoti
post Feb 16 2017, 04:03 PM
Post#1



Posts: 165
Joined: 29-June 05



Yes, I know it's not called a "field" but I can't remember the correct name. You know what I mean anyway!

On my form, I have a field named AttachedFile which may contain the name of a pdf file (e.g. Charente.pdf)
I want to open the pdf file. At the moment, I just have my PDF viewer which opens but no file.

I am having great difficulty in working out the exact path to that field and the file name therein. This is the line of text that is creating the problem.

This is what I have come to so far but cannot find the correct ending. It is fine as far as "\French". The database is called French.mbd
CODE
MyFilePath = "F:\Documents\LivingFrance\Properties\French & ME.txtAttachedFile"


Can anyone correct my mistake, please?

Many thanks in advance.
This post has been edited by ghoti: Feb 16 2017, 04:07 PM
Go to the top of the page
 
Doug Steele
post Feb 16 2017, 04:21 PM
Post#2


UtterAccess VIP
Posts: 21,357
Joined: 8-January 07
From: St. Catharines, ON (Canada)


CODE
MyFilePath = "F:\Documents\LivingFrance\Properties\French\" & ME.txtAttachedFile

--------------------
Go to the top of the page
 
ghoti
post Feb 17 2017, 03:13 PM
Post#3



Posts: 165
Joined: 29-June 05



Thanks very much for that Doug - but it does not work; I get the following message: "Method or Data member not found"

I've just spent the whole day trying to get the SHELL function to work, finally got it. However, I was using the path for the file in C:\ Test.pdf where I had a test file.

When I changed the path to F:\ etc, that message comes up

Any thoughts?
This post has been edited by ghoti: Feb 17 2017, 03:24 PM
Go to the top of the page
 
moke123
post Feb 17 2017, 03:52 PM
Post#4



Posts: 1,115
Joined: 26-December 12
From: Western Ma.,L.I.,N.Y.,Jupiter,Fl.



try putting a debug.print MyFilePath after the "MyFilePath = ..." line to be sure its correct
Go to the top of the page
 
ghoti
post Feb 17 2017, 04:48 PM
Post#5



Posts: 165
Joined: 29-June 05



I've just been playing around and this keeps coming up:

Expected end of statment: French\" & Me.AttachedFile, at the comma.

The MyFilePath is good; I place a test pdf file in the F:\ ... Properties\test.pdf and the file was displayed in the PDF viewer. So the problem must be after the last backslash, I think!

I found another website which gave the exact same as you did form the last "\":
C:\Sourcedocs\" & Me.sourcedoc, vbNormalFocus

Your offering is the same (as far as i can see) "F:\... French\" & Me.AttachedFile, vbNormalFocus
Most mysterious! Unless the problem is with "French" but I can't see how.

I've just run it again and now it says there is a syntax error.
Go to the top of the page
 
Doug Steele
post Feb 17 2017, 05:26 PM
Post#6


UtterAccess VIP
Posts: 21,357
Joined: 8-January 07
From: St. Catharines, ON (Canada)


Are you getting the error on the line where you assign a value to MyFilePath, or are you getting the error on a line where you're using MyFilePath?

If the latter, what's the line that's failing.

--------------------
Go to the top of the page
 
ghoti
post Feb 17 2017, 08:00 PM
Post#7



Posts: 165
Joined: 29-June 05



I wasn't able to get the debug.print to print anything.

My complete code is as follows:
CODE
Private Sub AttachedFile_DblClick(Cancel As Integer)

Dim ReaderPath As String
Dim MyFilePath As String
Dim RetVal

ReaderPath = "C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe"
MyFilePath = "F:\Documents\LivingFrance\Houses\French\ & Me.AttachedFile"    [b]'This is the problem line[/b]
'MyFilePath = "F:\Documents\LivingFrance\Houses\Charante.pdf"  This opens pdf viewer with pdf file using RetVal.
                
RetVal = Shell("""" & ReaderPath & """ """ & MyFilePath & """", vbNormalFocus)
          
End Sub


I originally had a folder named Properties but, as I thought in might conflict with the Properties in the database, I changed it to "Houses" and on the form I changed it to Maisons.

The problem area is "\ & Me.AttachedFile". I have checked the "AttachedFile" in the table and cannot find any error.
Go to the top of the page
 
Doug Steele
post Feb 17 2017, 09:44 PM
Post#8


UtterAccess VIP
Posts: 21,357
Joined: 8-January 07
From: St. Catharines, ON (Canada)


But that's not what I suggested you use. I'd said

CODE
MyFilePath = "F:\Documents\LivingFrance\Houses\French\" & Me.AttachedFile


You've got the reference to AttachedField (which I'm assuming is a text box on the form) inside the quotes. That means that you're getting & Me.AttachedFile in MyFilePath, not the content of the text box.

And what do you mean you couldn't get the Debug.Print to print anything? Where did you have the statement in your code? What were you trying to print?

--------------------
Go to the top of the page
 
ghoti
post Feb 18 2017, 07:24 AM
Post#9



Posts: 165
Joined: 29-June 05



***But that's not what I suggested you use. I'd said ***
Sorry about that. As what you said wasn't working, I was trying different things. I've spent 3 days tying to get this Shell to work. That line is back to what it should be though it does not work.

*** I'm assuming is a text box on the form ***
Correct

*** And what do you mean you couldn't get the Debug.Print to print anything? Where did you have the statement in your code? What were you trying to print? ***
You told me to place Debug.Print at the end of the line (the not working line) but it didn't print anything in the "Immediate" part of the VBA form code.

"French" is the name of the database (French.mdb). It is not a folder.

Do we need to tell the SHELL() function the name of the form (as there could be a number of forms though in this database there is only the one form? It is "Maisons".

I put a test pdf file in each of the folders and the file was opened perfectly. When I came the "French" that is when it stopped working - the pdf reader opened but no pdf file.

Now, I am not very good with VBA (as you have probably worked out!) but have tried many things after looking up various things on the internet. But nothing has worked. I am now relying on UtterAccess for the answer.

Many thanks for your help.
This post has been edited by ghoti: Feb 18 2017, 07:27 AM
Go to the top of the page
 
Doug Steele
post Feb 18 2017, 08:06 AM
Post#10


UtterAccess VIP
Posts: 21,357
Joined: 8-January 07
From: St. Catharines, ON (Canada)


What moke123 was suggesting was

CODE
Private Sub AttachedFile_DblClick(Cancel As Integer)
  
Dim ReaderPath As String
Dim MyFilePath As String
Dim RetVal
  
ReaderPath = "C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe"
MyFilePath = "F:\Documents\LivingFrance\Houses\French\" & Me.AttachedFile
Debug.Print "MyFilePath = " & MyFilePath
                
RetVal = Shell("""" & ReaderPath & """ """ & MyFilePath & """", vbNormalFocus)
          
End Sub

Once your code has run (and you got the error), go to the Debug Window (using Ctrl-G) and see what's been printed there. Let's assume it's F:\Documents\LivingFrance\Houses\French\SomeFile.pdf Select the file name then type the following into the Debug Window

CODE
Shell "C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe" "F:\Documents\LivingFrance\Houses\French\SomeFile.pdf"


Does that work, or do you get a slightly more meaningful error message?

--------------------
Go to the top of the page
 
ghoti
post Feb 18 2017, 10:02 AM
Post#11



Posts: 165
Joined: 29-June 05



Hi again, Doug.
So I got the debug working and it showed the following:
MyFilePath = F:\Documents\LivingFrance\Houses\French.mdb\Charante.pdf

However, it did name the file (Charante.pdf) that is in the "AttachedFile" field. So something is reading what is in the field.

Having run MyFilePath = F:\Documents\LivingFrance\Houses\French.mdb\Charante.pdf, I got a Compile Error: Syntax error.

I then put brackets around the whole line (as SHELL() has the brackets) and the error message was: Compile error - Expected list separator or )

We just need to find how to get it into the PDF Viewer!

Sorry for all the hassle and many thanks for sticking with it.
Go to the top of the page
 
Doug Steele
post Feb 18 2017, 11:43 AM
Post#12


UtterAccess VIP
Posts: 21,357
Joined: 8-January 07
From: St. Catharines, ON (Canada)


Sorry, I don't use PDFXCview.exe, so I can't offer any suggestions on what the syntax might be.

If what you put was actually
CODE
MyFilePath = F:\Documents\LivingFrance\Houses\French.mdb\Charante.pdf

it's not surprising you got an error. You need quotes

CODE
MyFilePath = "F:\Documents\LivingFrance\Houses\French.mdb\Charante.pdf"



--------------------
Go to the top of the page
 
moke123
post Feb 18 2017, 11:50 AM
Post#13



Posts: 1,115
Joined: 26-December 12
From: Western Ma.,L.I.,N.Y.,Jupiter,Fl.



QUOTE
"French" is the name of the database (French.mdb). It is not a folder.


why is the db name in the path?

try

CODE
MyFilePath = "F:\Documents\LivingFrance\Houses\Charante.pdf"

This post has been edited by moke123: Feb 18 2017, 11:53 AM
Go to the top of the page
 
Doug Steele
post Feb 18 2017, 01:07 PM
Post#14


UtterAccess VIP
Posts: 21,357
Joined: 8-January 07
From: St. Catharines, ON (Canada)


Well spotted, @moke123!

Sometimes I don't read as carefully as I should! blush.gif

--------------------
Go to the top of the page
 
moke123
post Feb 18 2017, 01:55 PM
Post#15



Posts: 1,115
Joined: 26-December 12
From: Western Ma.,L.I.,N.Y.,Jupiter,Fl.



got new eyeglasses ! cool.gif
This post has been edited by moke123: Feb 18 2017, 01:56 PM
Go to the top of the page
 
ghoti
post Feb 18 2017, 06:56 PM
Post#16



Posts: 165
Joined: 29-June 05



CODE
MyFilePath = "F:\Documents\LivingFrance\Houses\Charante.pdf"


"why is the db name in the path?"


Because it is one level up from
MyFilePath = "F:\Documents\LivingFrance\Houses\French\& Me.AttachedFile"

This proves that the line is perfect up to and including "Houses". And the file opens perfectly in the PDF Viewer.

Therefore the problem is somewhere in the remainder of the line, i.e. "French\ & Me.AttachedFile"

There is no issue with PDF Exchange viewer as it works even with the above code.

Now, if I put a "." at the end of the line, after French: "F\ ....\French." & Me.AttachedFile
the debugger gives the following: MyFilePath = F:\Documents\LivingFrance\Houses\French.Charante.pdf
So obviously the debugger is reading the line correctly but not the SHELL() or MyFilePath is missing something.

Go to the top of the page
 
moke123
post Feb 18 2017, 07:20 PM
Post#17



Posts: 1,115
Joined: 26-December 12
From: Western Ma.,L.I.,N.Y.,Jupiter,Fl.



if french is not a folder it does not belong in the file path.
Go to the top of the page
 
ghoti
post Feb 18 2017, 08:29 PM
Post#18



Posts: 165
Joined: 29-June 05



French is the name of the database - French.mdb

attached is a cut-down version of the database. Obviously, you will have to change the ReaderPath to your own pdf viewer.


You will find in the VBA coding some of my attempts at solving the issue. However, it is set at the moment to the line that is causing the problem.
This post has been edited by ghoti: Feb 18 2017, 08:32 PM
Attached File(s)
Attached File  French.zip ( 106.22K )Number of downloads: 6
 
Go to the top of the page
 
moke123
post Feb 18 2017, 09:18 PM
Post#19



Posts: 1,115
Joined: 26-December 12
From: Western Ma.,L.I.,N.Y.,Jupiter,Fl.



I think the problem is your path.

heres a sample db. It has a function for you to select a file and it will show you the path to that file.

I also included a function to open any file with the default application for that file type. I assume PDF Exchange viewer is your default program for pdf files so it should work.

Attached File  PathExample.zip ( 30.12K )Number of downloads: 5
Go to the top of the page
 
tina t
post Feb 18 2017, 10:49 PM
Post#20



Posts: 5,169
Joined: 11-November 10
From: SoCal, USA


PMFJI, but

QUOTE
"why is the db name in the path?"


Because it is one level up from
MyFilePath = "F:\Documents\LivingFrance\Houses\French\& Me.AttachedFile"

is your pdf file is stored in the database? it would have to be in an OLE field... anyway, if it is, you're not going to be able to open it the way you're going about it. actually, i don't know if you can externally open a file that's stored as an OLE object in a table, in A2003. i tend to think not, but don't have any experience to base that on.

if your pdf file is stored outside of the database, with just the filename stored in a Text field, then you need the filepath to the pdf file itself - and that has nothing to do with the database, or where the database file is stored.

hth
tina

--------------------
"you can't take the sky from me"
Go to the top of the page
 
2 Pages V  1 2 >


Custom Search
RSSSearch   Top   Lo-Fi    18th October 2017 - 04:12 AM