VBA - Visual Basic for Applications
Recently I had to link tables from one access file in another access file.
I did not intend to document such a trivial task on my webpage, but since the function I copied from the internet ran into an endless loop after I only provided an invalid file path I decided to implement something myself.
' Alexander Bolte
' Linking given table from given source Access database in CurrentDb under provided target name.
' If a linked table already exists under given name, the link will be broken and replaced with the new one.
' @Param strDatabaseSource
' String providing the full path of the source access database.
' @Param strTableSource
' String providing the source table name in the source access database.
' @Param strTableDestination
' String providing the target table name in CurrentDB.
' True, if linkage succeeded, else false.
Public Function LinkTable( _
ByVal strDatabaseSource As String, _
ByVal strTableSource As String, ByVal strTableDestination As String _
) As Boolean
Dim dbSource As DAO.Database
Dim dbTarget As DAO.Database
Dim dbDestination As DAO.Database
Dim tdf As DAO.TableDef
On Error GoTo LinkTable_Err
Set dbSource = DBEngine.Workspaces(0).OpenDatabase(strDatabaseSource)
Set dbDestination = CurrentDb
Set tdf = dbDestination.CreateTableDef(strTableDestination)
tdf.Connect = ";DATABASE=" & strDatabaseSource
tdf.SourceTableName = strTableSource
LinkTable = True
LinkTable_Err: If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, cDialogTitle
LinkTable = False
If Not (dbSource Is Nothing) Then
Set dbSource = Nothing
Set dbDestination = Nothing
Set tdf = Nothing
- Hits: 8451
The following methods provide you with three different ways of reading a range into a collection in VBA.
- Hits: 8130
The following looked simple enough for me.
Here a solution, which works for me however you have to be careful since it relies on a certain environment variable to be present. If this environment variable is not available the method automatically assumes the os to operate in 32 bit.
Unfortunately thie below did not work for me as it returned "x86" no matter if I started it on a 64 bit or 32 bit os.
- Hits: 8328
Excel VBA Article Count: 30
This category will hold articles regarding developement in Excel VBA. It will serve as a wiki and an Excel VBA Framework for myself.
Some development tasks reoccur for every customer. Since I am a lazy bum it will be nice to have a central source where I can reuse source code from.
MS Office and VBA Article Count: 11
This category holds articles regarding general things in MS Office VBA independent from the MS Office application.
Power Point VBA Article Count: 1
Page 5 of 17