dbTalk Databases Forums  

Word path from access - network

comp.databases.ms-access comp.databases.ms-access


Discuss Word path from access - network in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
David B
 
Posts: n/a

Default Word path from access - network - 01-13-2011 , 11:49 AM






Hi
I have a access database which has been working for a number of years on a
single computer.
I have just put it on a network - 1 machine has fe/be and 2 have fe

Some word documents can be opened from the home form by code from command
buttons with this example


Private Sub Command59_Click()
Dim Word As Object
Set Word = CreateObject("Word.Application")
Word.Visible = True
On Error Resume Next
Word.Documents.Open FileName:="C:\data\Dairy
Stuff\custletters\pricelist0608.doc"
If Err.Number = 5174 Then
MsgBox "YourFileField" & " not found"
Exit Sub
End If


End Sub


However the path on the main machine is now different to the other 2.

to avoid having to go into the code

My thought was to have a table in the be holding the paths with the main
machine 1 and the other two 2
The registation table on the front ends would carry 1 or2
then modify the code above to
If =DLookUp("[wordpath]","[REGISTRATIONtbl]")= 1 Then

At this point I`ve got stuck -
So is this the best approach and if so what do I need to follow with to get
the grab the path ?

TIA
David

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: Word path from access - network - 01-13-2011 , 01:34 PM






David B wrote:
Quote:
Hi
I have a access database which has been working for a number of years on a
single computer.
I have just put it on a network - 1 machine has fe/be and 2 have fe

Some word documents can be opened from the home form by code from command
buttons with this example


Private Sub Command59_Click()
Dim Word As Object
Set Word = CreateObject("Word.Application")
Word.Visible = True
On Error Resume Next
Word.Documents.Open FileName:="C:\data\Dairy
Stuff\custletters\pricelist0608.doc"
If Err.Number = 5174 Then
MsgBox "YourFileField" & " not found"
Exit Sub
End If


End Sub


However the path on the main machine is now different to the other 2.

to avoid having to go into the code

My thought was to have a table in the be holding the paths with the main
machine 1 and the other two 2
The registation table on the front ends would carry 1 or2
then modify the code above to
If =DLookUp("[wordpath]","[REGISTRATIONtbl]")= 1 Then

At this point I`ve got stuck -
So is this the best approach and if so what do I need to follow with to get
the grab the path ?

TIA
David

If you have 3 machines, 2 with the data mdb (backend) on the local C:
drive and another on a network, you might want to consider getting the
backend file name's path. Find a table that is linked. Let's pretend
it's called LinkedTableName.

The following function would be placed in a code module.

Public Function BEPath()
Dim s As String
Dim t As TableDef
Dim d As Database

Set d = CurrentDb

Set t = d.TableDefs("LinkedTableName")
s = Mid(t.Connect, 11) 'gets the backend file name
d.Close
Set d = Nothing

BEPath = Left(s, InStrRev(s, "\"))

End Function

If the Backend mdb is C:\Apps\Test\MyApp.mdb, the above function will
return C:\Apps\Test\.

If you were to change the line to
BEPath = Left(s, 3)
it would return C:\.

Thus you could concatenate like

Word.Documents.Open FileName:=bepath() &
"\data\DairyStuff\custletters\pricelist0608.do c" and it would be expand
to C:\data\DairyStuff\custletters\pricelist0608.doc if it were on the C:
drive.

Reply With Quote
  #3  
Old   
David-W-Fenton
 
Posts: n/a

Default Re: Word path from access - network - 01-14-2011 , 05:28 PM



Salad <salad (AT) oilandvinegar (DOT) com> wrote in
news:kLWdndgDaaNOzrLQnZ2dnUVZ_r2dnZ2d (AT) earthlink (DOT) com:

Quote:
Public Function BEPath()
Dim s As String
Dim t As TableDef
Dim d As Database

Set d = CurrentDb

Set t = d.TableDefs("LinkedTableName")
s = Mid(t.Connect, 11) 'gets the backend file name
d.Close
Set d = Nothing

BEPath = Left(s, InStrRev(s, "\"))

End Function
What's the point here of initializing a database variable? Why not
just have the function be this:

Public Function BEPath(strTable As String) As String
Dim strTemp As String

strTemp = Mid(CurrentDB.TableDefs(strTable).Connect, 11)
PathFromFileName = Left(strTemp, InStrRev(strTemp, "\")
End Function

Or, better yet, two functions:

Public Function BEDatabase(strTableName As String) As String
BEDatabase = Mid(CurrentDB.TableDefs(strTableName).Connect, 11)
End Function

Public Function PathFromFileName(strPath As String) As String
PathFromFileName = Left(strPath, InStrRev(strTemp, "\")
End Function

....and then you'd get the path to the back end with:

?PathFromFileName(BEDatabase("MyTable"))

....and you have a function, PathFromFileName, that can be used to
get the path from any file name.

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
  #4  
Old   
David B
 
Posts: n/a

Default Re: Word path from access - network - 01-15-2011 , 09:09 AM



Thanks for the ideas, much appreciated
DB


"David-W-Fenton" <dfassoc (AT) dfenton (DOT) com> wrote

Quote:
Salad <salad (AT) oilandvinegar (DOT) com> wrote in
news:kLWdndgDaaNOzrLQnZ2dnUVZ_r2dnZ2d (AT) earthlink (DOT) com:

Public Function BEPath()
Dim s As String
Dim t As TableDef
Dim d As Database

Set d = CurrentDb

Set t = d.TableDefs("LinkedTableName")
s = Mid(t.Connect, 11) 'gets the backend file name
d.Close
Set d = Nothing

BEPath = Left(s, InStrRev(s, "\"))

End Function

What's the point here of initializing a database variable? Why not
just have the function be this:

Public Function BEPath(strTable As String) As String
Dim strTemp As String

strTemp = Mid(CurrentDB.TableDefs(strTable).Connect, 11)
PathFromFileName = Left(strTemp, InStrRev(strTemp, "\")
End Function

Or, better yet, two functions:

Public Function BEDatabase(strTableName As String) As String
BEDatabase = Mid(CurrentDB.TableDefs(strTableName).Connect, 11)
End Function

Public Function PathFromFileName(strPath As String) As String
PathFromFileName = Left(strPath, InStrRev(strTemp, "\")
End Function

...and then you'd get the path to the back end with:

?PathFromFileName(BEDatabase("MyTable"))

...and you have a function, PathFromFileName, that can be used to
get the path from any file name.

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
  #5  
Old   
a a r o n . k e m p f @gmail.com [MCITP: DBA]
 
Posts: n/a

Default Re: Word path from access - network - 01-15-2011 , 11:11 AM



Wow, I just use SQL Server Reporting Services to do stuff like this
(write word docs).

It's MUCH better solution than Word automation or exporting jet
reports to DOC





On Jan 13, 9:49*am, "David B" <david.bay... (AT) btconnect (DOT) com> wrote:
Quote:
Hi
I have a access database which has been working for a number of years on a
single computer.
I have just put it on a network - 1 machine has fe/be and 2 have fe

Some word documents can be opened from the home form by code from command
buttons with this example

Private Sub Command59_Click()
Dim Word As Object
Set Word = CreateObject("Word.Application")
Word.Visible = True
On Error Resume Next
Word.Documents.Open FileName:="C:\data\Dairy
Stuff\custletters\pricelist0608.doc"
If Err.Number = 5174 Then
* *MsgBox "YourFileField" & " not found"
* *Exit Sub
End If

End Sub

However *the path on the main machine is now different to the other 2.

to avoid having to go into the code

My thought was to have a table in the be holding the paths with the main
machine 1 and the other two 2
The registation table on the front ends would carry 1 or2
then modify the code above to
If =DLookUp("[wordpath]","[REGISTRATIONtbl]")= 1 Then

At this point I`ve got stuck -
So is this the best approach and if so what do I need to follow with to get
the grab the path ?

TIA
David

Reply With Quote
  #6  
Old   
Salad
 
Posts: n/a

Default Re: Word path from access - network - 01-15-2011 , 11:26 AM



David-W-Fenton wrote:

Quote:
Salad <salad (AT) oilandvinegar (DOT) com> wrote in
news:kLWdndgDaaNOzrLQnZ2dnUVZ_r2dnZ2d (AT) earthlink (DOT) com:


Public Function BEPath()
Dim s As String
Dim t As TableDef
Dim d As Database

Set d = CurrentDb

Set t = d.TableDefs("LinkedTableName")
s = Mid(t.Connect, 11) 'gets the backend file name
d.Close
Set d = Nothing

BEPath = Left(s, InStrRev(s, "\"))

End Function


What's the point here of initializing a database variable? Why not
just have the function be this:

Public Function BEPath(strTable As String) As String
Dim strTemp As String

strTemp = Mid(CurrentDB.TableDefs(strTable).Connect, 11)
PathFromFileName = Left(strTemp, InStrRev(strTemp, "\")
End Function

Or, better yet, two functions:

Public Function BEDatabase(strTableName As String) As String
BEDatabase = Mid(CurrentDB.TableDefs(strTableName).Connect, 11)
End Function

Public Function PathFromFileName(strPath As String) As String
PathFromFileName = Left(strPath, InStrRev(strTemp, "\")
End Function

...and then you'd get the path to the back end with:

?PathFromFileName(BEDatabase("MyTable"))

...and you have a function, PathFromFileName, that can be used to
get the path from any file name.

Any idea why this code fails?
Dim t As TableDef
Dim s as string
Set t = CurrentDb.TableDefs("SomeTableName")
s = Mid(t.Connect, 11) 'gets the backend file name

It says Object invalid is not longer set.

Reply With Quote
  #7  
Old   
Bob Barrows
 
Posts: n/a

Default Re: Word path from access - network - 01-15-2011 , 12:13 PM



Salad wrote:

Quote:
Any idea why this code fails?
Dim t As TableDef
Dim s as string
Set t = CurrentDb.TableDefs("SomeTableName")
s = Mid(t.Connect, 11) 'gets the backend file name

It says Object invalid is not longer set.
You have a much better chance of figuring that out than we do. Step through
the code with the debugger and make sure the object variables are set. It's
likely to be the t variable since that's the only object variable in this
code snippet. Perhaps you supplied the wrong tabledef name ... ?

Reply With Quote
  #8  
Old   
Salad
 
Posts: n/a

Default Re: Word path from access - network - 01-15-2011 , 01:12 PM



Bob Barrows wrote:

Quote:
Salad wrote:


Any idea why this code fails?
Dim t As TableDef
Dim s as string
Set t = CurrentDb.TableDefs("SomeTableName")
s = Mid(t.Connect, 11) 'gets the backend file name

It says Object invalid is not longer set.


You have a much better chance of figuring that out than we do. Step through
the code with the debugger and make sure the object variables are set. It's
likely to be the t variable since that's the only object variable in this
code snippet. Perhaps you supplied the wrong tabledef name ... ?


If I add a
Dim d as database
set d = currentdb
and modify the Set t line to
Set t = d.tabledefs("SomeTableName")
it works.

Yet if works fine using David's code which was
s = Mid(CurrentDB.TableDefs(strTableName).Connect, 11)

Reply With Quote
  #9  
Old   
Bob Barrows
 
Posts: n/a

Default Re: Word path from access - network - 01-15-2011 , 01:59 PM



Salad wrote:
Quote:
Bob Barrows wrote:

Salad wrote:


Any idea why this code fails?
Dim t As TableDef
Dim s as string
Set t = CurrentDb.TableDefs("SomeTableName")
s = Mid(t.Connect, 11) 'gets the backend file name

It says Object invalid is not longer set.


You have a much better chance of figuring that out than we do. Step
through the code with the debugger and make sure the object
variables are set. It's likely to be the t variable since that's the
only object variable in this code snippet. Perhaps you supplied the
wrong tabledef name ... ?
If I add a
Dim d as database
set d = currentdb
and modify the Set t line to
Set t = d.tabledefs("SomeTableName")
it works.

Yet if works fine using David's code which was
s = Mid(CurrentDB.TableDefs(strTableName).Connect, 11)
Let me see if I can reproduce that in A2007 ... yes, I can easily reproduce
it. Now that I went through the exercise, I do vaguley remember this issue
but I no longer remember why it doesn't work. Something about the implicit
database variable returned by CurrentDB in memory going out of scope as soon
as the statement finishes executing. Change it to

Dim t As TableDef
Dim s As String
Set t = DBEngine(0)(0).TableDefs("tblinvoices")
s = Mid(t.Connect, 11) 'gets the backend file name

and it works fine

Reply With Quote
  #10  
Old   
Salad
 
Posts: n/a

Default Re: Word path from access - network - 01-15-2011 , 02:43 PM



Bob Barrows wrote:

Quote:
Salad wrote:

Bob Barrows wrote:


Salad wrote:



Any idea why this code fails?
Dim t As TableDef
Dim s as string
Set t = CurrentDb.TableDefs("SomeTableName")
s = Mid(t.Connect, 11) 'gets the backend file name

It says Object invalid is not longer set.


You have a much better chance of figuring that out than we do. Step
through the code with the debugger and make sure the object
variables are set. It's likely to be the t variable since that's the
only object variable in this code snippet. Perhaps you supplied the
wrong tabledef name ... ?

If I add a
Dim d as database
set d = currentdb
and modify the Set t line to
Set t = d.tabledefs("SomeTableName")
it works.

Yet if works fine using David's code which was
s = Mid(CurrentDB.TableDefs(strTableName).Connect, 11)


Let me see if I can reproduce that in A2007 ... yes, I can easily reproduce
it. Now that I went through the exercise, I do vaguley remember this issue
but I no longer remember why it doesn't work. Something about the implicit
database variable returned by CurrentDB in memory going out of scope as soon
as the statement finishes executing. Change it to

Dim t As TableDef
Dim s As String
Set t = DBEngine(0)(0).TableDefs("tblinvoices")
s = Mid(t.Connect, 11) 'gets the backend file name

and it works fine


That it does. Thanks for the update.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.