zelarra821
Registered User.
- Local time
- Today, 23:12
- Joined
- Jan 14, 2019
- Messages
- 847
Goodnight.
As I say in the matter, I have a divided database and I want to produce a procedure that tells me if the backend exists, and if it does not exist, to open a window to choose the path where it is located.
I have this code from @MajP, but I do not know how to remove the code that I do not need exactly for what I want, and what I am doing is chaining procedures and functions that may not work for me.
My idea is to put it in a module to use it only in the split databases.
If you know of another simpler system, let me know.
Thanks a lot.
As I say in the matter, I have a divided database and I want to produce a procedure that tells me if the backend exists, and if it does not exist, to open a window to choose the path where it is located.
I have this code from @MajP, but I do not know how to remove the code that I do not need exactly for what I want, and what I am doing is chaining procedures and functions that may not work for me.
Code:
Private Sub Form_Open(Cancel As Integer)
' Tests a linked table for valid back-end.
On Error GoTo Err_Form_Open
Dim strTest As String, db As dao.Database
Dim td As dao.TableDef
DoCmd.RunCommand acCmdAppMaximize
DoCmd.Minimize
Me.Visible = False
Set db = CurrentDb
Dim lngRtn As Long
For Each td In db.TableDefs
If Len(td.Connect) > 0 Then ' Is a linked table.
On Error Resume Next ' Turn off error trap.
strTest = Dir(Mid(td.Connect, 11)) ' Check file name.
On Error GoTo Err_Form_Open ' Turn on error trap.
If Len(strTest) = 0 Then ' No matching file.
lngRtn = MsgBox("Couldn't find the back-end file " & _
Mid(td.Connect, 11) & "." & vbCrLf & vbCrLf & "Please choose your database backend that has your data tables.", _
vbExclamation + vbOKCancel + vbDefaultButton1, _
"Can't find backend data file.")
If lngRtn = vbOK Then
strPath = GetFileDialog() ' Open prompt form.
If Len(strPath) > 0 Then ' user responded, put selection into text box on form.
'MsgBox strPath, vbInformation, "New Path"
Call ProcessTables
Else
MsgBox "No Back End Data Base Selected. Exiting Application", vbExclamation, "Must Select BE database."
DoCmd.Quit
End If
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "f_MainMenu", , , , , acDialog
Exit Sub ' to refresh links
Else
MsgBox "The linked tables can't find their source. " & _
"Please log onto network and restart the application."
Exit Sub
End If
End If
End If
Next ' Loop to next tabledef.
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "f_mainMenu", , , , , acDialog
Exit_Form_Open:
Exit Sub
Err_Form_Open:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_Form_Open
End Sub
My idea is to put it in a module to use it only in the split databases.
If you know of another simpler system, let me know.
Thanks a lot.