Sunday, July 16, 2006

How to create a single-user ACT! 2006 database with the ACT! SDK

Below is the code that I developed to create a new ACT! 2006 Premium database on a Windows XP machine via the ACT! 2006 SDK.

There can be numerous situations where you will want to create a blank new ACT! database with just the standard ACT! fields.

Please note that you must have at least one CLY layout file in the Layouts folder in order to open the database from ACT! 2006.

This routine has only been certified for non-shared, i.e., single-user databases. Parameter bShared=False.

I hope you find this useful, please let me know if you do.

ACT! is a registered trademark of Sage Software SB, Inc. See for more information.

Joe Kunk
Listen IT Solutions, LLC
jkunk at listenit dot com

Public Function CreateNewACTDatabase(ByVal DBName As String, ByVal dbLocation As String, ByVal UserName As String, ByVal Password As String, ByVal bShared As Boolean, ByVal SourceLayoutFolder As String) As String

'Returns PAD filename if successful, otherwise null
'Return an empty string if an error in the parameters

If DBName.Trim.Length = 0 Then Return String.Empty
If dbLocation.Trim.Length = 0 Then Return String.Empty
If UserName.Trim.Length = 0 Then Return String.Empty
If SourceLayoutFolder.Trim.Length = 0 Then Return String.Empty
If Not IO.Directory.Exists(dbLocation) Then Return String.Empty
If Not IO.Directory.Exists(SourceLayoutFolder) Then Return String.Empty

'Sample standalone database PAD File
'<?xml version="1.0" standalone="no"?>
'<!DOCTYPE ACTDatabasePADFile>
'<!--This file represents a Pointer to an Act Database or [PAD]-->
'<ACTDatabase name="ACT_Standalone_Test_2006" host="." location="C:\Test" type="Sql" />

'Sample shared database PAD file
'<?xml version="1.0" standalone="no"?>
'<!DOCTYPE ACTDatabasePADFile>
'<!--This file represents a Pointer to an Act Database or [PAD]-->
'<ACTDatabase name="ACT_Shared_Test_2006" host="MYPCNAME" location="C:\Test" type="Sql" />

'Declare the ACT! Framework object
Dim cAFF As New Act.Framework.ActFramework

'Declare GeneratePADFile=True as a constant
Const GeneratePADFile As Boolean = True

'Now actually create the database, calling routine should have warned user that could take a couple minutes
Dim strPadFileName As String = _
cAFF.CreateActDatabase(DBName, dbLocation, bShared, UserName, Password, GeneratePADFile)

'Exit with an empty string if CreateACTDatabase function failed
If strPadFileName.Trim.Length = 0 Then Return String.Empty

'Set up the Path variables for both the Source and Destination CLY files
Dim CLY_Source_Path As String = SourceLayoutFolder
If Not CLY_Source_Path.EndsWith("\") Then CLY_Source_Path &= "\"
Dim CLY_Dest_Path As String = dbLocation & "\" & DBName & "-database files\Layouts\"

'Get the list of all CLY files in the Source folder and copy each one to the Dest folder
Dim dir As New System.IO.DirectoryInfo(SourceLayoutFolder)
Dim f As System.IO.FileInfo
For Each f In dir.GetFiles("*.cly")
f.CopyTo(CLY_Dest_Path & f.Name, True)
Next f

Return strPadFileName

End Function

No comments: