Build from Source with PowerShell script #430
-
I have a system that consists of few .accdb files (approx. 10 files) and when I check out a new branch, I want to be able to build the files from source with a script instead of opening every individual file and run the add-in. I have been able to create new files and opened them from script but I have been stuck on compiling them from source. Has any one done this before or have any idea how I can accomplish this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@StolpiJanus - If you use the latest beta version (4.0.21) you should be able to include the following code snippet in your database. You can then call this from your script via COM automation, or using a macro with the /x command line switch. '---------------------------------------------------------------------------------------
' Procedure : ExampleBuildFromSource
' Author : Adam Waller
' Date : 9/6/2023
' Purpose : This function can be copied to a local database and triggered with a
' : command line argument or other automation technique to load the VCS
' : add-in file and build this project from source.
' : NOTE: This expects the add-in to be installed in the default location
' : and using the default file name.
'---------------------------------------------------------------------------------------
'
Public Function ExampleBuildFromSource()
Dim strAddInPath As String
Dim proj As Object ' VBProject
Dim objAddIn As Object ' VBProject
' Build default add-in path
strAddInPath = Environ$("AppData") & "\MSAccessVCS\Version Control.accda"
' See if add-in project is already loaded.
For Each proj In VBE.VBProjects
If StrComp(proj.FileName, strAddInPath, vbTextCompare) = 0 Then
Set objAddIn = proj
End If
Next proj
' If not loaded, then attempt to load the add-in.
If objAddIn Is Nothing Then
' The following lines will load the add-in at the application level,
' but will not actually call the function. Ignore the error of function not found.
' https://stackoverflow.com/questions/62270088/how-can-i-launch-an-access-add-in-not-com-add-in-from-vba-code
On Error Resume Next
Application.Run strAddInPath & "!DummyFunction"
On Error GoTo 0
' See if it is loaded now...
For Each proj In VBE.VBProjects
If StrComp(proj.FileName, strAddInPath, vbTextCompare) = 0 Then
Set objAddIn = proj
End If
Next proj
End If
If objAddIn Is Nothing Then
MsgBox "Unable to load Version Control add-in. Please ensure that it has been installed" & vbCrLf & _
"and is functioning correctly. (It should be available in the Add-ins menu.)", vbExclamation
Else
' Set the application interaction level to silent to skip confirmation dialogs.
Application.Run "MSAccessVCS.SetInteractionMode", 1
' Launch the build process (as if we clicked the button on the ribbon)
Application.Run "MSAccessVCS.HandleRibbonCommand", "btnBuild"
End If
End Function I was doing some testing with PowerShell a few weeks ago, and was successfully using something like the following: $app = New-Object -ComObject "Access.Application"
# make the object visible
$app.Visible = -1
$app.RunCommand(10)
$app.OpenCurrentDatabase("C:\path\to\database\Testing.accdb")
# Load add-in
try
{
$app.Run("C:\Users\awaller\AppData\Roaming\MSAccessVCS\VERSION CONTROL.ACCDA!DummyFunction")
}
catch
{
# No problem if an error was thrown. The important thing is that we loaded the add-in.
}
# Set the application interaction level to silent to skip confirmation dialogs.
$app.Run("MSAccessVCS.SetInteractionMode", [ref]1)
$app.Run("MSAccessVCS.HandleRibbonCommand", [ref]"btnBuild")
#$app.Quit() |
Beta Was this translation helpful? Give feedback.
@StolpiJanus - If you use the latest beta version (4.0.21) you should be able to include the following code snippet in your database. You can then call this from your script via COM automation, or using a macro with the /x command line switch.