path syntax error

J

Joanne

I am trying to print a document as a result of the user choice from a
combo box.
Here is my code
I keep getting a syntax error on on the strpath = current project
line.
I've tried parens in different spots, and quotes in different spots
but can't get rid of the message for 'expected bracketed etc'

Please take a look and get me pointed in the right direction
Thanks a great deal

Private Sub cboBenefits_AfterUpdate()
Dim strPath As String
Dim oWordApp As Word.Application


strPath = CurrentProject."C:\NMWorkPackage" & "\" &
Me!cboBenefits"


Set oWordApp = New Word.Application
oWordApp.Documents.Open strPath
oWordApp.PrintOut

End Sub
 
B

Brendan Reynolds

I'm not quite clear what you're trying to do on that line, Joanne. If your
document is in the same folder as the MDB in which this code is running,
then what you want is the Path property of the CurrentProject object. If, on
the other hand, you're going to use the hard-coded path C:\NMWorkPackage
then you should remove the reference to CurrentProject. For example ...

strPath = CurrentProject.Path & "\" & Me!cboBenefits

.... or ...

strPath = "C:\NMWorkPackage\" & Me!cboBenefits

A third possibility is that the path to the documents could be relative to
the location of the MDB in which the code is running, e.g. the documents are
in a folder called NMWorkPackage that is a subfolder of the folder that
contains the MDB. In that case the syntax would be ...

strPath = CurrentProject.Path & "\NMWorkPackage\" & Me!cboBenefits

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
J

Joanne

Brendan
Thanks for your prompt reply
My files and mdb are in the same folder, c:\NMWorkPackage

So I am using the currentproject.path line
(I think my first mistake here was to assume that I needed to list the
actual path instead of using the 'currentproject.path' itself, so now
I get that.)

But I am still having a problem with the path but now I am thinking
that I am confused about the value of the combo box.
MY dilema is this
I created the combo box based on a table with 3 fields.
Field 1 - the path to the doc (C:\NMWorkPackage)
Field 2 - The doc name as I wanted it to appear to the user
Field 3 - The group name the doc belongs to, such as "Benefits"

In the wizard, they recommended I hide the first field, so I did. Now
my combo box properties shows only 2 fields, binding to field #1,
which is the proper file name for the user, but not the file as named
in the subdirectory, so I wonder if the value of my combo box is not
correctly drawn from the right column and if that is the case, could
it this causing my problem with the path.

I made a dummy combo box on my form, and did not hide the column 1 as
the wizard suggests, and on this combo box I had 3 columns, with #1
being the bound column, which has the path to the file in it.

I think I am a bit confused on how to go about this procedure

Bottom line is, I list my files in my combo box, when the user chooses
one I want ot open word (I know how to do this) show the file, give
the user a chance to print it if they want to (using msgbox vbyesno
for this)
and then I will simply close the doc, close word and return to my
access app.
 
B

Brendan Reynolds

Well, what we need is the *actual* name of the file, as it is stored in the
folder. Not the path, which we can get from CurrentProject.Path, and not the
name as you want the user to see it if that differs from the actual file
name. If all documents have the same extension, we can leave that out, but
if different documents can have different extensions, then we'll need to
include the extension too.

Let's assume, for now, that we store the name including the extension. So if
the file is saved as "Readme.doc", then "Readme.doc" is in one of the
columns of the combo box. If that column is the bound column of the combo
box, then the example I gave earlier will work ...

strPath = CurrentProject.Path & "\" & Me!NameOfCombo

If the column that contains the document name is *not* the bound column,
then we need to use the Column property of the combo box to refer to the
column that contains the document name. The Column property is zero-based,
so the first column is Column(0), the second column is Column(1), etc. So if
our document name is in the second column, our code would become ...

strPath = CurrentProject.Path & "\" & Me!NameOfCombo.Column(1)

Finallly, if all documents have the same extension and we have decided not
to include the extension in the combo box, we can add the extension in the
code ...

strPath = CurrentProject.Path & "\" & Me!NameOfCombo.Column(1) & ".doc"

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
J

Joanne

Brendan
That clears it up nicely. My confusion came from the statement
"CurrentProject.Path" that I was so unfamiliar with that I thought the
.path part needed to be filled in with my actual path to the files.
Now I get it!! Thank you so much for your help, but I would like to
beg one more explanation from you.

Say I wanted to print all of the docs in a folder.

I know how to do the for/next statement to iterate thru each doc, and
to create the word app, but what I don't know how to do is to tell the
routine where to get the files to open them for print.

In other words, how do I create the recordset from the directory to
show my routine what it is I want to print out.

I think I need to do this in the subroutine for printing and I know I
must create the recordset before running the for/next statement to do
the printing.
Do I use a query to open the files I want and ifso, how do I get the
query results into the coding so the printing can be accomplished?

Thanks a bunch for your time and help
 
B

Brendan Reynolds

Sorry, Joanne, I'm afraid I couldn't quite follow the question. I *think* it
sounds like you want to automate Microsoft Word from Microsoft Access, and
Word automation is something that I haven't done recently. If no one else
answers your question here, I'd suggest posting it as a new question in a
new thread.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
J

Joanne

Brendan
Mayabe this will help explain where I am having problems understanding
what is going on.

I got this code to print all docs from an mvp on one of the boards.

Public Sub PrintAll()
Dim oWordapp As Object
Set oWordapp = GetObject(, "Word.Application")
Dim oDoc As Object
With oWordapp
For Each oDoc In oWordapp.Documents
oDoc.PrintOut Background = False
oDoc.Saved = True ' or save it if you like
oDoc.Close
Next
End With
oWordapp.Quit
End Sub

It doesn't work and I think that it is becuase there are no open docs
because I don't see anywhere that they were opened from.

So I tried to add this line
Set oDoc = Dir("C:\NMWorkPackage\*.doc")
by I get a type mismatch error on the 'Dir' word.
If I change the type to 'dim oDoc as String (instead as Object)' I get
this error:
For Each control must be variable or object

I am really stymied.

So I thought to use another mvp's advise and get a recordset of the
docs in the directory with a sql statement but once I have run the sql
statement I do not understand how to use the recordset to point to the
files and then to run the printall code on it.

Is this any clearer to you - myself, I am going in circles around the
problem I fear.

Thanks again for your time and consideration
 
B

Brendan Reynolds

This is a new question, Joanne. I volunteered to answer the original
question about the syntax error, and I believe I have done that. I suggest
you post your new question as a new thread, with a descriptive subject line,
so that other volunteers can decide whether that is a question they wish to
answer. If I understand you correctly, I would suggest that the subject line
should be something along the lines of 'how to print all the word documents
in a folder'.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 

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