![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| |||
| |||
|
|
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 |
#4
| |||
| |||
|
|
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/ |
#5
| |||
| |||
|
|
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 |
#6
| |||
| |||
|
|
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. |
#7
| |||
| |||
|
|
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. |
#8
| |||
| |||
|
|
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 |
#9
| |||
| |||
|
|
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) |
#10
| |||
| |||
|
|
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. |
![]() |
| Thread Tools | |
| Display Modes | |
| |