Function MakeTable(TableName As String) As Boolean
Dim strSQL As String, Db As DAO.Database
' Creates a table (TableName) with data = to the WHERE clause.
'On Error GoTo errhandler
'---=== Create the Update SQL Code from our values ===---
'---=== "TableName" Created based on EDS Net ID Field on "SAL Lookup" form. FROM "Letter Information" table. WHERE "Letter Information" table = Criteria (values) from specific form. ===---
'---=== Begin Letter Preview Code ===---
If CurrentProject.AllForms("Provider Letters").IsLoaded Then
strSQL = "SELECT * INTO " & TableName & " FROM [Letter Information] WHERE" _
& "((([Letter Information].Analyst)='" & Forms![Provider Letters]![Analyst] & "') AND" _
& "(([Letter Information].[Letter Type])='" & Forms![Provider Letters]![Letter Type] & "')AND" _
& "(([Letter Information].[Letter Date]) = #" & Forms![Provider Letters]![Letter Date] & "#)AND" _
& "(([Letter Information].[Provider Name])='" & Forms![Provider Letters]![Provider Name] & "'));"
ElseIf CurrentProject.AllForms("Letter Search - Results").IsLoaded Then
strSQL = "SELECT * INTO " & TableName & " FROM [Letter Information] WHERE" _
& "((([Letter Information].Analyst)='" & Forms![Letter Search - Results]![Analyst] & "') AND" _
& "(([Letter Information].[Letter Type])='" & Forms![Letter Search - Results]![Letter Type] & "')AND" _
& "(([Letter Information].[Letter Date]) = #" & Forms![Letter Search - Results]![Letter Date] & "#)AND" _
& "(([Letter Information].[Provider Name])='" & Forms![Letter Search - Results]![Provider Name] & "'));"
ElseIf CurrentProject.AllForms("Search Form").IsLoaded Then
If Screen.ActiveControl.Name = "Print-LD" Then
strSQL = "SELECT * INTO " & TableName & " FROM [Letter Information] WHERE" _
& "((([Letter Information].Analyst)='" & Forms![Search Form]![Analyst-C] & "') AND" _
& "(([Letter Information].[Letter Type])='" & Forms![Search Form]![Letter Type-C] & "')AND" _
& "(([Letter Information].[Letter Date]) = #" & Forms![Search Form]![Letter Date] & "#));"
ElseIf Screen.ActiveControl.Name = "Print" Then
strSQL = "SELECT * INTO " & TableName & " FROM [Letter Information] INNER JOIN [Letter Search - Query] ON [Letter Information].ID = [Letter Search - Query].ID WHERE" _
& "((([Letter Information].ID)='" & Forms![Search Form]![SID] & "'));"
'strSQL = "SELECT * INTO " & TableName & " FROM [Letter Information] INNER JOIN [Letter Search - Query] ON [Letter Information].ID = [Letter Search - Query].ID WHERE" _
'& "((([Letter Information].ID)='" & Forms![Search Form]![SID] & "'));"
Else:
MsgBox "Failure", , "Failure"
End If
Else:
'Do Nothing
End If
'----=== End Letter Preview Code ===----
'Use Current Database
Set Db = CurrentDb()
'Run the SQL Query
Debug.Print strSQL
Db.Execute strSQL
'If no errors return true
MakeTable = True
ExitHere:
Set Db = Nothing
Exit Function
errhandler:
'There is an error return false
MakeTable = False
With Err
MsgBox Err.Number & " - " & Err.Description, vbExclamation, "Make Table Function Error..."
End With
Resume ExitHere
End Function