RE:Vincular tablas automáticamente
Algo complicado pero interesante... en el evento al abrir del formulario principal pones =VTablas()
y cargate este codigo en un modulo adaptandolo a lo tuyo.... si tienes pega me pones un mensaje .
Function VTablas() As Boolean
Dim ActualDB As Database
Dim ETabla As TableDef
Dim ModuloServidorFile As String
Dim Contador As Integer
Dim kk As String
ModuloServidorFile = OpenFile()
If ModuloServidorFile <> "" Then
VTablas = True
Set ActualDB = CurrentDb()
For Contador = 0 To ActualDB.TableDefs.Count - 1
Set ETabla = ActualDB.TableDefs(Contador)
If ETabla.Connect <> "" And Right(ETabla.Connect, 11) <> "ACCESOS.MDB" Then
kk = Right(ETabla.Connect, 11)
ETabla.Connect = ";DATABASE=" & ModuloServidorFile
Err = 0
ETabla.RefreshLink
If Err <> 0 Then
MsgBox "La conexión con el Módulo Servidor ha sido insatisfactoria." & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "'" & ModuloServidorFile & "' no contiene la tabla '" & ETabla.SourceTableName & "' requerida por la aplicación.", vbCritical + vbOKOnly, "Conexión con el Servidor"
VTablas = False
Exit For
End If
End If
Next Contador
Else
MsgBox "La conexión con el Módulo Servidor ha sido cancelada.", vbCritical + vbOKOnly, "Conexión con el Servidor"
VTablas = False
End If
End Function
Private Function OpenFile() As String
Dim of As OPENFILENAME
of.hwndOwner = Application.hWndAccessApp
of.hInstance = 0
of.lpstrCustomFilter = 0
of.nMaxCustrFilter = 0
of.lpfnHook = 0
of.lpTemplateName = 0
of.lCustrData = 0
of.lpstrFilter = "RPMCDatos" & vbNullChar & "*.mde" & vbNullChar & vbNullChar
of.nFilterIndex = 1
of.lpstrFile = Left$("RPMCDatos.mde" & String$(512, 0), 512)
of.nMaxFile = 511
of.lpstrFileTitle = String$(512, 0)
of.nMaxFileTitle = 511
of.lpstrTitle = "Vincular B.D."
of.lpstrInitialDir = "C:\Archivo de Programa\Dorlet"
of.lpstrDefExt = ""
of.flags = OFN_EXPLORER + OFN_FILEMUSTEXIST + OFN_NOCHANGEDIR + OFN_PATHMUSTEXIST + OFN_HIDEREADONLY
of.lStructSize = Len(of)
If GetOpenFileName(of) Then
OpenFile = Trim(Left$(of.lpstrFile, InStr(of.lpstrFile, vbNullChar) - 1))
Else
OpenFile = ""
End If
End Function