Private Function Tst_Dpt() As Boolean
Dim bMM As Boolean
Dim bValue As Boolean
bMM = IsOpen("frmMainMenu")
If bMM = True Then
bValue = Nz(Forms!frmMainMenu!sfrmRpts.Form.cDpt, False)
End If
bMM = IsOpen("sfrmRpts")
If bMM = True Then
bValue = Nz(Forms!sfrmRpts.cDpt, False)
End If
If g_bLoadDept = True Or bValue = True Then Tst_Dpt = True
End Function
'Form Open goes before Form Load in MS Access
Private Sub Form_Open(Cancel As Integer)
Set_Data
End Sub
Private Sub Set_Data()
Dim sSQL As String
Dim sMeName As String
Dim sStdName As String
Dim sShwName As String
Dim sTblName As String
sMeName = Me.Form.Name
sTblName = Replace(sMeName, "sfrmShw", "")
sStdName = Replace(sMeName, "sfrmShw", "std")
sShwName = Replace(sMeName, "sfrmShw", "shw")
If This_Table_Exists(sStdName) = False Then
sSQL = "SELECT " & KeyCode & ", " & KEYNAME & ", [Show], 0 AS Sort INTO " & sStdName
sSQL = sSQL & " FROM " & sTblName
CurrentDb.Execute sSQL
DoEvents
End If
If This_Table_Exists(sShwName) = False Then
sSQL = "SELECT " & KeyCode & ", " & KEYNAME & ", [Show], 0 As Sort INTO " & sShwName
sSQL = sSQL & " FROM " & sStdName
CurrentDb.Execute sSQL
DoEvents
End If
If Tst_Dpt = False Then
sSQL = "DELETE * FROM [" & sShwName & "]"
CurrentDb.Execute sSQL
sSQL = "INSERT INTO [" & sShwName & "] ( " & KeyCode & ", " & KEYNAME & ", Show, Sort )"
sSQL = sSQL & " SELECT '" & SELECTCODE & "' AS " & KeyCode & ", '" & SELECTALL & "' AS " & KEYNAME & ", True AS Show, 0 AS Sort"
CurrentDb.Execute sSQL
sSQL = "INSERT INTO " & sShwName & " ( [" & KeyCode & "], [" & KEYNAME & "], Show, Sort )"
sSQL = sSQL & " SELECT [" & sStdName & "].[" & KeyCode & "], ' ' & [" & KEYNAME & "] AS DptName, [" & sStdName & "].[Show], 1 AS DptS"
sSQL = sSQL & " FROM [" & sStdName & "]"
CurrentDb.Execute sSQL
End If
sSQL = "SELECT " & KeyCode & ", " & KEYNAME & ", Show, Sort"
sSQL = sSQL & " FROM " & sShwName
sSQL = sSQL & " ORDER BY Sort, " & KEYNAME
Me.RecordSource = sSQL
End Sub
Public Function IsOpen(ByVal strformname As String) As Boolean
On Error GoTo Err_IsOpen
Const conDesignView = 0
Const conObjStateClosed = 0
IsOpen = False
If SysCmd(acSysCmdGetObjectState, acForm, strformname) <> conObjStateClosed Then
If Forms(strformname).CurrentView <> conDesignView Then
IsOpen = True
End If
End If
Exit_IsOpen:
Exit Function
Err_IsOpen:
Call Error_Action(Err, Err.description, "modGlobal @ IsOpen", Erl())
Resume Exit_IsOpen
End Function
|