If InvTblExists(Me.projectkey, "File") = False Then
CreateFileList (Me.projectkey)
' MsgBox "There is no File Table"
End If
Public Function InvTblExists(PKey As String, FType As String)
Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
Dim csql As String
Dim strTempID As String
Dim tableToFind As String
tableToFind = PKey & FType & "List"
con.ConnectionString = "Provider=SQLNCLI11;" _
& "Server=lit-sql;" _
& "Database=123DriveInventories;" _
& "Integrated Security=SSPI;" _
& "DataTypeCompatibility=80;" _
& "MARS Connection=True;"
con.Open
Set cmd.ActiveConnection = con
cmd.CommandText = "SELECT COUNT(*) FROM sys.objects WHERE Type = 1 AND [Name]='" & tableToFind & "'"
Set rst = cmd.Execute
strTempID = rst.Fields(0).Value
'MsgBox strTempID & " Is the return value!"
If strTempID = 0 Then
strExists = "False"
Else
strExists = "True"
End If
con.Close
Set con = Nothing
End Function
Public Function CreateFileList(PKey As String)
Dim con As Connection
Dim cmd As Command
Dim rst As Recordset
Dim csql As String
Dim strTempID As String
'con.ConnectionString = "Provider=SQLNCLI11;" _
' & "Server=MySQLServerABC001;" _
' & "Database=123DriveInventories;" _
' & "Integrated Security=SSPI;" _
' & "DataTypeCompatibility=80;" _
' & "MARS Connection=True;"
'con.Open
'
'Set cmd.ActiveConnection = con
'cmd.CommandText = "CREATE TABLE [123DriveInventories].[dbo].[" & PKey & "FileList]([id] [int] IDENTITY(1,1) NOT NULL, " & _
' "[FKDrive] [int] NULL, " & _
' "[FileName] [nvarchar](255) NULL, " & _
' "[Extension] [nvarchar](255) NULL, " & _
' "[FileSize] [bigint] NULL, " & _
' "[ModifiedDate] [datetime] NULL, " & _
' "[FullPathName] [nvarchar](4000) NULL, " & _
' "[FullPathMAX] [nvarchar](max) NULL, " & _
' "[createdate] [datetime] NULL, " & _
' "[modifydate] [datetime] NULL, " & _
' "[createuser] [nvarchar](50) NULL, " & _
'"CONSTRAINT [PK_" & PKey & "FileList] PRIMARY KEY CLUSTERED " & _
'"([Id] Asc) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] " & _
'"GO SET ANSI_PADDING OFF " & _
'"GO ALTER TABLE [123DriveInventories].[dbo].[" & PKey & "FileList] ADD CONSTRAINT [DF_" & PKey & "FileList_createdate] DEFAULT (getdate()) FOR [createdate] " & _
'"GO ALTER TABLE [123DriveInventories].[dbo].[" & PKey & "FileList] ADD CONSTRAINT [DF_" & PKey & "FileList_modifydate] DEFAULT (getdate()) FOR [modifydate] " & _
'"GO CREATE TRIGGER [123DriveInventories].[dbo].[" & PKey & "FileList_MODS] ON [dbo].[" & PKey & "FileList] AFTER UPDATE AS SET NOCOUNT ON " & _
'"GO UPDATE [123DriveInventories].[dbo].[" & PKey & "FileList] SET " & PKey & "FileList.[Modified] = getdate(), " & PKey & "FileList.[ModifiedBy] = User FROM DELETED d WHERE " & PKey & "FileList.Id = d.Id"
'
'Set rst = cmd.Execute
'strTempID = rst.Fields(0).Value
If InvTblExists(PKey, "File") = False Then
MsgBox "Failed to create " & PKey & "FileList table!! Oh No!"
End If
con.Close
Set con = Nothing
End Function