Print all open docs

M

Malcolm Smith

Joanne

Can you post the whole code which was failing as in your message to me?
This will have the document variable name after the .Open method


Now, as an aside doing stuff like:

sFileName.open

won't work as sFileName is not an object (it's just a string) and,
therefore, it doesn't have the .Open method.

Anyway, just post the whole of the code with the sFileName variable in
place so I can see what is going wrong.

- Malc
 
J

Joanne

Public Sub PrintAll(sGroupName As String)

Dim oWordapp As Object
Set oWordapp = CreateObject("Word.Application")
Dim oDocName As Object
Dim oRst As DAO.Recordset
Dim sSql As String
Dim sFilename As String

sSql = "SELECT tblDocumentList.FileName FROM tblDocumentList" & _
" WHERE (((tblDocumentList.GroupName) = """ & _
sGroupName & """));"

Set oRst = CurrentDb.OpenRecordset(sSql)

If Not oRst Is Nothing Then
Do While Not oRst.EOF
sFilename = "" & oRst("Filename")
If Len(Dir$(sFilename)) > 0 Then
Set oDocName = oWordapp.Documents.Open
If Not oDocName Is Nothing Then
oDocName.PrintOut
oDocName.Saved = True
oDocName.Close
End If
End If

oRst.MoveNext
Loop
End If

oWordapp.Quit

End Sub

I investigated my sFileName.Open and found what you are saying. I need
to keep methods = object as versus variables = value straight in my
head.

Here is the code, and thank you for doing this
 
M

Malcolm Smith

Joanne

I will knock up a small Access database and see what is going wrong.

Looking at this code it seems that the only thing which is wrong is that
you are not passing the sFileName to the oWordApp.Documents.Open method.

But, you say that you have tried this?

- Malc
 
J

Joanne

Malcolm
When I use a break to stop the action at the

If Len(Dir$(sFilename)) > 0 Then

Then the immediate window reports the correct sFileName and the
correct sGroupName

but ONLY if I do not put sFileName at the end of this line:
Set oDocName = oWordapp.Documents.Open
If I add sFileName to the above line, I get the compile / syntax error

If you want any or all of the elements of this database to help with
the troubleshooting and save you any time, please just say so and I
will send it to you

Thanks for your time and efforts
 
J

Jay Freedman

Hi Joanne,

Place parentheses around the parameter:
Set oDocName = oWordapp.Documents.Open(sFileName)

VBA has a rule (IHMO complete nonsense, but strictly enforced by the
compiler) that you *must* have parentheses around the parameter list
of a *function* call (i.e., one that returns a value), and you *must
not* have parentheses around the parameter list of a *subroutine*
call. Since you're using the return value of the Open method to assign
oDocName, you're treating the method as a function, hence the
parentheses are required.

Furthermore, the filename parameter is required -- otherwise the
method wouldn't know what file to open.
 
M

Malcolm Smith

Hi Joanne,

Place parentheses around the parameter:

Bloody Nora! Been staring at this issue for so long I never saw that.

This is something that one does as a matter of fact, but when writing code
in a text editor then sometimes one misses the blindingly obvious. Still,
I did put a caveat in there somewhere once about code written from the top
of my head...

- Malc
 
J

Joanne

Hi Jay
Thanks for jumping into the battle with Malcolm and I

I did as you said, but still if I set the breakpoint at the line with
the Dir$ coding in it and the (sFileName) in place after .open, I get
nothing returned in my variables. If I don't put (sFileName) in
place, and run it to the Dir$ line, my correct values are in the
variables.

I haven't a clue what is going on here

Thanks for your time Jay, I appreciate the help, and needing
parentheses is a great bit of information for me for the future.
 
J

Joanne

Malcolm

I did as Jay said, but still if I set the breakpoint at the line with
the Dir$ coding in it and the (sFileName) in place after .open, I get
nothing returned in my variables. If I don't put (sFileName) in
place, and run it to the Dir$ line, my correct values are in the
variables.

I haven't a clue what is going on here

I oftentimes go 'blind' when I am coding. The littelest thing can
cause so much grief!! I always say you have to be extremely 'detail
oriented' to program or you will spend your days banging your head on
the desktop.

It's a lot like cooking - taste the dish 3 or 4 times and then I can
no longer tell what it needs. Look at the code for awhile, and I can
no longer see the tiny details.

Thanks for your help on this, but I'm afraid it still isn't going.
I am about to print out your code for this routine (I will use it as
example for my next projects) and perhaps just rebuild this app. Could
the problem be something as simple as my having renamed my table
fields in the middle of the process?
 
M

Malcolm Smith

I did as you said, but still if I set the breakpoint at the line with
the Dir$ coding in it and the (sFileName) in place after .open, I get
nothing returned in my variables.

Which variables? If you are talking about the oDocName then that isn't a
simple variable as such, but an Object. Best to view that in the Watch
list.

Or do you get the value 'Nothing' for this 'variable'?

- Malc
www.dragondrop.com
 

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