My Assistant
|
|
Feb 23 2012, 09:43 PM
Post
#1
|
|
|
New Member Posts: 6 From: Adelaide, South Australia |
So I'm trying to migrate an existing database to a front end/back end model as part of having multiple user access.
Unfortunately the database creates a new table for each day it is used (very rarely as it is). I've managed to get the front end to create the new table in the backend and link it, however the other front ends don't see this new table. I tried the following code found from Google to automatically add all tables from a backed database, but it doesn't seem to work. I suspect it may be because it's looking for an mdb file, whereas my backend is an accdb... Thoughts? I realise this is a horrible way to do it and it makes me cry every time I have to patch stuff, but I'm not in the position where I can rewrite the application from scratch (the previous developer even has spaces and slashes in field names!) CODE '
'Link All Tables From Back End Database ' 'The function LinkTables creates links to all the tables in the remote database. 'The DbPath parameter should contain the complete path and database name. 'The subroutine CallLinkTables has sample code to call the function. Function LinkTables(DbPath As String) As Boolean 'This links to all the tables that reside in DbPath, whether or not they already reside in this database. 'This works when linking to an Access .mdb file, not to ODBC. 'This keeps the same table name on the front end as on the back end. Dim rs As Recordset On Error Resume Next 'get tables in back end database Set rs = CurrentDb.OpenRecordset("SELECT Name " & _ "FROM MSysObjects IN '" & DbPath & "' " & _ "WHERE Type=1 AND Flags=0") If Err <> 0 Then Exit Function 'link the tables While Not rs.EOF If DbPath <> Nz(DLookup("Database", "MSysObjects", "Name='" & rs!Name & "' And Type=6")) Then 'delete old link, assuming front and back end table have the same name DoCmd.DeleteObject acTable, rs!Name 'make new link DoCmd.TransferDatabase acLink, "Microsoft Access", DbPath, acTable, rs!Name, rs!Name End If rs.MoveNext Wend rs.Close LinkTables = True End Function Sub CallLinkTables() Dim Result As Boolean 'sample call: Result = LinkTables("C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb") Debug.Print Result End Sub |
|
|
|
TheWedgie Load All Tables From Backend Database Feb 23 2012, 09:43 PM
theDBguy Hi,
What version of Access are you using? Knowi... Feb 24 2012, 12:17 AM
TheWedgie QUOTE (theDBguy @ Feb 24 2012, 04:17 PM) ... Feb 24 2012, 12:29 AM
theDBguy Hi,
Did you try stepping through the code?
Just ... Feb 24 2012, 12:43 AM
pere_de_chipstick PMFJI
In A2007 (and probably A2010) the "DoCm... Feb 24 2012, 03:41 AM
TheWedgie Thanks pere - although with that code I get an ... Feb 24 2012, 06:26 PM
MadPiet Just wondering, but what's this doing or suppo... Feb 24 2012, 07:53 PM
pere_de_chipstick Hi MadPiet
Good catch - Thanks - 'db' is... Feb 25 2012, 05:22 AM
TheWedgie Marvellous - that fixed it.
Although the (linked) ... Feb 26 2012, 05:13 AM
pere_de_chipstick You can prevent the code linking unwanted tables b... Feb 26 2012, 08:56 AM![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 18th May 2013 - 01:24 PM |