help with code

G

Guest

I copied this code from this site. It looked like it would work for me. I
am trying to scan documents into a folder and give the document a name
Contract*.pdf With their client id after contract.

However I keep getting an error 490. I know the problem is in the
strfilespec line, but I can't fiqure it out. I'm just learning to code. If
I leave off the & strfilespec on the last line it takes me to the correct
directory. Thanks for any help.


Private Sub Command126_Click()
Dim strFilespec As String
Const CONTRACTS_FOLDER = "\\server\data\mgt\"

strFilespec = "Contract_" & Format(Me.clientid, "000000") & ".pdf"
Application.FollowHyperlink CONTRACTS_FOLDER & strFilespec

End Sub
 
R

Rick Brandt

sue said:
I copied this code from this site. It looked like it would work for
me. I am trying to scan documents into a folder and give the
document a name Contract*.pdf With their client id after contract.

However I keep getting an error 490. I know the problem is in the
strfilespec line, but I can't fiqure it out. I'm just learning to
code. If I leave off the & strfilespec on the last line it takes me
to the correct directory. Thanks for any help.


Private Sub Command126_Click()
Dim strFilespec As String
Const CONTRACTS_FOLDER = "\\server\data\mgt\"

strFilespec = "Contract_" & Format(Me.clientid, "000000") & ".pdf"
Application.FollowHyperlink CONTRACTS_FOLDER & strFilespec

End Sub

That code is trying to OPEN the file at the specified location. That has
nothing to do with "scan documents into a folder and give the document a
name Contract*.pdf".

You'll need to be more specific about what you are attempting to accomplish.
If you are trying to CREATE files then FollowHyperlink is not going to get
it done.
 
G

Guest

Sorry for not being clear. I have scanned documents into the mgt folder on
my network. I am trying to open the documents based upon the name ex:
contract_000123.pdf would belong to client 000123. I hope this helps.
Thanks for the response,
 
R

Rick Brandt

sue said:
Sorry for not being clear. I have scanned documents into the mgt
folder on my network. I am trying to open the documents based upon
the name ex: contract_000123.pdf would belong to client 000123. I
hope this helps. Thanks for the response,

In that case I see nothing wrong with your current code. Add a line of
code...

Private Sub Command126_Click()
Dim strFilespec As String
Const CONTRACTS_FOLDER = "\\server\data\mgt\"
strFilespec = "Contract_" & Format(Me.clientid, "000000") &".pdf"
Debug.Print CONTRACTS_FOLDER & strFilespec
Application.FollowHyperlink CONTRACTS_FOLDER & strFilespec
End Sub

....and then check the output of the Print in the VBA debug window. It might
show you what is wrong.
 
G

Guest

I really hate to be such a pest but I don't know how to "....and then check
the output of the Print in the VBA debug window. It might show you what is
wrong."

Thanks for the help.
 
R

Rick Brandt

sue said:
I really hate to be such a pest but I don't know how to "....and then
check the output of the Print in the VBA debug window. It might
show you what is wrong."

Thanks for the help.

The line...
Debug.Print CONTRACTS_FOLDER & strFilespec

....will cause the result of that expression to be evaluated and written to
the Immediate pane visible in the VBA editor. Just press <Ctl-G> to open
that window after running your code. You should see the results there.
 
G

Guest

I got the immediate pane, but it's blank.

Rick Brandt said:
The line...
Debug.Print CONTRACTS_FOLDER & strFilespec

....will cause the result of that expression to be evaluated and written to
the Immediate pane visible in the VBA editor. Just press <Ctl-G> to open
that window after running your code. You should see the results there.
 
G

Guest

I am looking at it after I run it. But I am really out of my league. I'm
not sure we are talking the same language. Here's my code, I really
appreciate your help.

Private Sub Command126_Click()
Dim strFilespec As String
Const CONTRACTS_FOLDER = "\\mchdnt\data\mgt\"
strFilespec = "Contract_" & Format(Me.clientid, "000000") & ".pdf"
Debug.Print CONTRACTS_FOLDER & strFilespec
Application.FollowHyperlink CONTRACTS_FOLDER & strFilespec
End Sub
 
G

Guest

If I take off the & & strFilespec on the last line I get me path and filename
in the immediate pane. Hope this helps.

Sue
 
R

Rick Brandt

sue said:
If I take off the & & strFilespec on the last line I get me path and
filename in the immediate pane. Hope this helps.

I don't understand. strFileSpec is where you had the file name stored. If you
remove that from the Debug.Print line then you should NOT be getting your file
name in the immediate window. You would only get "\\mchdnt\data\mgt\".
 
G

Guest

This is what I get in the pane when I take off the & strFilespec

\\mchdnt\data\mgt\Contract_000001.pdf

Thanks again
 
R

Rick Brandt

sue said:
This is what I get in the pane when I take off the & strFilespec

\\mchdnt\data\mgt\Contract_000001.pdf

You are either missing something or we are talking past each other. Running
this code (copied from your last post)...

Private Sub Command126_Click()
Dim strFilespec As String
Const CONTRACTS_FOLDER = "\\mchdnt\data\mgt\"
strFilespec = "Contract_" & Format(Me.clientid, "000000") & ".pdf"
Debug.Print CONTRACTS_FOLDER & strFilespec
Application.FollowHyperlink CONTRACTS_FOLDER & strFilespec
End Sub

I would expect to see \\mchdnt\data\mgt\Contract_000001.pdf in the immediate
pane. If you remove & strFilespec leaving...

Private Sub Command126_Click()
Dim strFilespec As String
Const CONTRACTS_FOLDER = "\\mchdnt\data\mgt\"
strFilespec = "Contract_" & Format(Me.clientid, "000000") & ".pdf"
Debug.Print CONTRACTS_FOLDER
Application.FollowHyperlink CONTRACTS_FOLDER & strFilespec
End Sub

....it is simply NOT possible for you to see
\\mchdnt\data\mgt\Contract_000001.pdf in the immediate window unless you
didn't clear it from a previous run. Did you do that? The immediate pane
doesn't automatically clear itself unless you close and reopen the file or
Access.
 
G

Guest

I removed & file spec from the application.followhyperlink line of code.

Private Sub Command126_Click()
Dim strFilespec As String
Const CONTRACTS_FOLDER = "\\mchdnt\data\mgt\"
strFilespec = "Contract_" & Format(Me.clientid, "000000") & ".pdf"
Debug.Print CONTRACTS_FOLDER & strFilespec
Application.FollowHyperlink CONTRACTS_FOLDER
End Sub

THanks
 
R

Rick Brandt

sue said:
I removed & file spec from the application.followhyperlink line of
code.

Private Sub Command126_Click()
Dim strFilespec As String
Const CONTRACTS_FOLDER = "\\mchdnt\data\mgt\"
strFilespec = "Contract_" & Format(Me.clientid, "000000") & ".pdf"
Debug.Print CONTRACTS_FOLDER & strFilespec
Application.FollowHyperlink CONTRACTS_FOLDER
End Sub

A) That should have nothing to do with what you see in the immediate window.

B) That is not going to open a file if all you are doing is pointing at a
folder.

You can also test certain code in the immediate window. In that window (on
a new line) type...

Application.FollowHyperlink "\\mchdnt\data\mgt\Contract_000001.pdf" <enter>

When you press <enter> does it work?
 
G

Guest

run time error 490, can't open file

Rick Brandt said:
A) That should have nothing to do with what you see in the immediate window.

B) That is not going to open a file if all you are doing is pointing at a
folder.

You can also test certain code in the immediate window. In that window (on
a new line) type...

Application.FollowHyperlink "\\mchdnt\data\mgt\Contract_000001.pdf" <enter>

When you press <enter> does it work?
 
R

Rick Brandt

sue said:
run time error 490, can't open file

That would suggest that either the file does not exist, the path does not
exist, or you don't have sufficient permissions to the folder and/or file.
When you come up with an expression that DOES work in the immediate window
then you can use that to get your code working.
 
G

Guest

I have admin rights and the file is there. I think the problem is in this
line of code:

strFilespec = "Contract_" & Format(Me.clientid, "000000") & ".pdf"

I don't even know what it is supposed to do, but what I thought it did was
lfind the document with the 6 digits from the client #. Basically I wanted
to match contract_000123 with client 000123.

If you don't want to keep fighting this with me I understand, you've been
more than generous. Thanks again.
 
R

Rick Brandt

sue said:
I have admin rights and the file is there. I think the problem is in
this line of code:

strFilespec = "Contract_" & Format(Me.clientid, "000000") & ".pdf"

But when you previously ran the line of code in the immediate window the
line of code above is not in the picture at all and yet you say you still
got an error.
I don't even know what it is supposed to do, but what I thought it
did was lfind the document with the 6 digits from the client #.
Basically I wanted to match contract_000123 with client 000123.

Basically all your code is doing is building a string argument on-the-fly
from two separate pieces and then using those pieces as the argument for
FollowHyperlink.

However; in the immediate window you executed a line of code with a
hard-coded literal value for the FollowHyperlink argument and it didn't
work. Until you get the hard-coded statement to work you can't expect to be
able to dynamically generate that argument string and have it work.
If you don't want to keep fighting this with me I understand, you've
been more than generous. Thanks again.

Simpler (hopefully) example...

Dim FormNamePart1 as String
Dim FormNamePart2 as String

FormNamePart1 = "MyForm"
FormNamePart2 = "Example"
DoCmd.OpenForm FormNamePart1 & FormNamePart2

The last line above is equivelant to...
DoCmd.OpenForm "MyFormExample"

In your case...
DoCmd.OpenForm "MyFormExample"

....produces an error. Given that, it is impossible for...
DoCmd.OpenForm FormNamePart1 & FormNamePart2

....to work. Rather than worrying about why the statement using variables
doesn't work you first have to figure out why the statement that does NOT
use variables doesn't work. Until you have that figured out the rest makes
no difference.
 
G

Guest

Ok, I will work from that angle. Thanks again for all your help. I really
appreciate your time and talent.

Sue
 

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