danick5000 said:
The users will have the databas on their own local hard drives. But
the path to the BE will be different for each user. So when I send
them a new FE, they will have to re-link the BE tables manually. Is
there any way to automate this with a button? They are not very
computer friendly users.
Rather long message but here is one way I handle relinking.
Mostly I tell users to put FE and BE in same folder.
Mike Gramelspacher
Ferdinand, Indiana
First of all download this code:
1. Call the standard File Open/Save dialogbox
http://www.mvps.org/access/api/api0001.htm
2. Relink Access tables from code
http://www.mvps.org/access/tables/tbl0009.htm
3. Reconnect attached tables on Startup
http://allenbrowne.com/ser-13.html
This function goes in general module with the above code downloads:
'-------------------------------------------------------------------
' Procedure : InitOk
' DateTime : 12/6/2004 08:15
' Author : Allen Browne
' Purpose : Set InitOK to True or False depending whether a recordset
' : based on a linked table can be successfully opened.
'--------------------------------------------------------------------
'
Function InitOk(strLinkedTable As String) As Boolean
Dim rs As DAO.Recordset
On Error Resume Next
Set rs = CurrentDb.OpenRecordset(strLinkedTable)
InitOk = (Err.Number = 0)
rs.Close
Set rs = Nothing
End Function
Below is the only code I have on the starting form. If InitOK is True,
then tables do not have to be relinked. It InitOK is False then call
download no. 3. If the backend is in a different folder, open the
starting form and see if the user wants to browse for the file. I have
three possible switchboard forms, so that is reason for the extra code.
'--------------------------------------------------------------------
' Procedure : cmdBrowse_Click
' DateTime : 12/5/2004 21:25
' Author : Mike Gramelspacher
' Purpose : If reconnect does not work for the current directory, then
' : allow user to browse to a different folder and select
file.
'--------------------------------------------------------------------
'
Private Sub cmdBrowse_Click()
Dim FileFound As Boolean
' call function to browse for the new location of data file
FileFound = fRefreshLinks
' new location was found and data file relinked, so open index form
If FileFound Then
' get configuration from config table and assign menu name
' and to global variables
gstrMenuName = Nz(DFirst("MenuName", "tblConfig"), "frmMenu3")
'.. and assign minimum required characters for search forms
' to global variables
gintCharacters = Nz(DFirst("SearchCharNo", "tblConfig"), 1)
DoCmd.OpenForm gstrMenuName
End If
End Sub
'-----------------------------------------------------------------------
--
' Procedure : Form_Open
' DateTime : 12/5/2004 21:45
' Author : Mike Gramelspacher
' Purpose : If back end is already connected, then cancel this open
and
' : just open normal form, else try current folder first, and
if
' : not found there, allow user to browse for file.
'-----------------------------------------------------------------------
---
'
Private Sub Form_Open(Cancel As Integer)
' try to open a recordset with this table
If Not InitOk("tblCommunions") Then
' did not work, so change folder name of data file to current
folder name
' and try to relink data file
If Not Reconnect = True Then
' did not work, so continue opening this form
End If
Else
' get configuration from config table and assign menu name
' and search character minimum to global variables
gstrMenuName = Nz(DFirst("MenuName", "tblConfig"), "frmMenu3")
gintCharacters = Nz(DFirst("SearchCharNo", "tblConfig"), 1)
' it worked, so open index form and cancel opening this form
DoCmd.OpenForm gstrMenuName
Cancel = True
End If
End Sub