home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Accounting2021969272006.psc / Access_Functions.bas < prev    next >
BASIC Source File  |  2001-01-17  |  43KB  |  1,057 lines

  1. Attribute VB_Name = "Primary_Function"
  2. Option Explicit
  3.  
  4. Public Function CheckNewDB(ADOprimaryrs As ADODB.Recordset, FormType As String) As Boolean
  5.   With ADOprimaryrs
  6.     If .RecordCount = 0 Then
  7.         MsgBox FormType & " is empty. Creating new " & FormType & ".", vbInformation, "Information"
  8.         
  9.         CheckNewDB = True
  10.         Exit Function
  11.     End If
  12.   End With
  13.   CheckNewDB = False
  14. End Function
  15.  
  16. Public Function GetcheckNumber(db As ADODB.Connection, BankAcctID As String) As String
  17.   Dim rsBank As ADODB.Recordset
  18.   Set rsBank = New ADODB.Recordset
  19.   rsBank.Open "SELECT * FROM [Bank Accounts] WHERE [BANK ACCT ID]='" & BankAcctID & "'", db, adOpenStatic, adLockOptimistic
  20.   If rsBank.RecordCount = 0 Then
  21.      MsgBox "There is an error on Bank setup!", vbCritical, "Critical Error"
  22.      GetcheckNumber = "Error"
  23.      Exit Function
  24.   End If
  25.   GetcheckNumber = rsBank("BANK ACCT Next Check No")
  26.   rsBank.Close
  27.   Set rsBank = Nothing
  28. End Function
  29.  
  30. Public Function DataDelete(ADOprimaryrs As ADODB.Recordset, frm As Form, UseOrderBy As Boolean) As Boolean
  31. ShowStatus True
  32. On Error GoTo DeleteErr
  33. If ADOprimaryrs.RecordCount > 0 Then
  34.   With ADOprimaryrs
  35.         If .AbsolutePosition = 1 And UseOrderBy = False Then
  36.            MsgBox "Deleting first record is not allowed. Deleting instruction is cancelled", vbInformation, "Information"
  37.            DataDelete = False
  38.            ShowStatus False
  39.            Exit Function
  40.         End If
  41.  
  42.         If .EditMode <> 0 Then
  43.           .CancelUpdate
  44.         End If
  45.         'MsgBox .EditMode & "   " & "adEditNone = " & adEditNone & " adEditInProgress = " & adEditInProgress & " adEditAdd = " & adEditAdd & " adEditDelete = " & adEditDelete
  46.         .Delete
  47.         On Error GoTo exit_sub
  48.         If .EOF Then
  49.             .MoveFirst
  50.         Else
  51.             .MovePrevious
  52.         End If
  53.   End With
  54.   DataDelete = True
  55. End If
  56.  
  57.   ShowStatus False
  58.   Exit Function
  59. DeleteErr:
  60.   ShowStatus False
  61.   DataDelete = False
  62. exit_sub:
  63.   DataDelete = True
  64. End Function
  65.  
  66.  
  67. Public Function DataGridKnownError(DataError As Integer) As Boolean
  68.     Select Case DataError
  69.     Case 6153, 7007
  70.     'this is a known error but does not affect the result so i disable the messageBox
  71.     '     MsgBox "DataError : " & DataError & " This Error gives no Harm... but if someone knows how " & vbCr & "to fix this please e-mail to erricoe@TBS.com" & vbCr & " Under Subject: e-mail Razi...He needs my Help", vbCritical, "Known Bugs"
  72.          DataGridKnownError = True
  73.     Case 7011
  74.     'occured when deleting process is cancell
  75.          DataGridKnownError = True
  76.     Case 6152
  77.     '---
  78.          DataGridKnownError = False
  79.     Case Else
  80.          DataGridKnownError = False
  81.     End Select
  82.  
  83. End Function
  84.  
  85.  
  86. Public Function UnloadForm(ADOprimaryrs As ADODB.Recordset) As Integer
  87. On Error Resume Next
  88. If CloseAllActive = True Or ADOprimaryrs.RecordCount = 0 Then
  89.     ADOprimaryrs.CancelUpdate
  90.     ADOprimaryrs.Close
  91.     Set ADOprimaryrs = Nothing
  92.     UnloadForm = 0
  93.     Exit Function
  94. Else
  95.     With ADOprimaryrs
  96.     If .EditMode <> adEditNone And .EditMode <> adEditAdd Then
  97.     Dim CreateOrder As Integer
  98.     CreateOrder = MsgBox("Attempting to close the application. " & vbCr & "Would you like to update the data?", vbYesNoCancel, "Exiting")
  99.         If CreateOrder = vbYes Then
  100.            'If .Status = adRecModified Or .Status = adRecNew Then .Update
  101.            .Update
  102.            .Close
  103.            Set ADOprimaryrs = Nothing
  104.            UnloadForm = 0
  105.         ElseIf CreateOrder = vbCancel Then
  106.            UnloadForm = 1
  107.         Else
  108.            'If .Status = adRecModified Or .Status = adRecNew Then .CancelUpdate
  109.            .CancelUpdate
  110.            ADOprimaryrs.Close
  111.            Set ADOprimaryrs = Nothing
  112.            UnloadForm = 0
  113.         End If
  114.     Else
  115.            .CancelUpdate
  116.            ADOprimaryrs.Close
  117.            Set ADOprimaryrs = Nothing
  118.            UnloadForm = 0
  119.     End If
  120.     
  121.     End With
  122. End If
  123. End Function
  124.  
  125. Public Function CheckDocument(SQLstatement As String, db As ADODB.Connection, Optional ShowMessage As Boolean, Optional txtCallType As TextBox, Optional lblCallType As String) As Boolean
  126. ShowStatus True
  127. Dim dbCnn As ADODB.Connection
  128. Dim cbRS As ADODB.Recordset
  129. 'Dim i As Integer
  130.  
  131.   'Set dbCnn = New ADODB.Connection
  132.   'dbCnn.CursorLocation = adUseClient
  133.   'dbCnn.Open gblADOProvider
  134.   'Debug.Print SQLstatement
  135.   
  136.   Set cbRS = New ADODB.Recordset
  137.   With cbRS
  138.     'MsgBox SQLStatement
  139.     .Open SQLstatement, db, adOpenKeyset, adLockReadOnly, adCmdText
  140.     If .RecordCount > 0 Then
  141.        'trap this error
  142.        If ShowMessage = True Then
  143.             MsgBox "The value is already in used!", vbCritical, "Error"
  144.        End If
  145.        CheckDocument = False
  146.        GoTo FalseFlag
  147.     End If
  148.   .Close
  149.   End With
  150. CheckDocument = True
  151.  
  152. Dim Response As Integer
  153.  
  154. If txtCallType Is Nothing Then
  155. Else
  156.     If lblCallType = "" Then
  157.         lblCallType = fMainForm.ActiveForm.lblfields(txtCallType.Index).Caption
  158.     End If
  159.     Response = MsgBox("This is a new input for " & lblCallType & " , would you like to add it to the database?", vbYesNo, "Information")
  160.     If Response = vbYes Then
  161.     
  162.         Select Case lblCallType '
  163.         Case "Bank Account"
  164.             frm_SYS_Setup_Chart_Of_Accounts.CallByUserCOA txtCallType.Text, fMainForm.ActiveForm.lblfields(txtCallType.Index).Caption
  165.             frm_SYS_Setup_Chart_Of_Accounts.ZOrder 0
  166.             MsgBox "New data have been transferred to CHART OF ACCOUNT, but you have to add more data and save it.", vbInformation, "Information"
  167.         Case "COA"
  168.             frm_SYS_Setup_Chart_Of_Accounts.CallByUserCOA txtCallType.Text, fMainForm.ActiveForm.lblfields(txtCallType.Index).Caption
  169.             frm_SYS_Setup_Chart_Of_Accounts.ZOrder 0
  170.             MsgBox "New data have been transferred to CHART OF ACCOUNT, but you have to add more data and save it.", vbInformation, "Information"
  171.         Case "Customer ID"
  172.             frm_AR_Customer.CallByUserCust txtCallType.Text
  173.             frm_AR_Customer.ZOrder 0
  174.             MsgBox "New data have been transferred to CUSTOMER SETUP, but you have to add more data and save it.", vbInformation, "Information"
  175.         Case "Shipping ID"
  176.             frm_AR_Cust_Ship_To.CallByUserShip txtCallType.Text
  177.             frm_AR_Cust_Ship_To.ZOrder 0
  178.             MsgBox "New data have been transferred to SHIP TO SETUP, but you have to add more data and save it.", vbInformation, "Information"
  179.         End Select
  180.         txtCallType.Text = " "
  181.     Else
  182.         txtCallType.Text = " "
  183.     End If
  184. End If
  185. FalseFlag:
  186. Set cbRS = Nothing
  187. 'dbCnn.Close
  188. 'Set dbCnn = Nothing
  189. ShowStatus False
  190. End Function
  191.  
  192. 'for each control whose input you wish to validate, just put something like this
  193. 'in the KeyPress event of the control-->>keyResponse=CtrlValidate(Keyascii, "$.0123456789")
  194. 'Doing so will filter out any undesired keys that go to the control, accepting
  195. 'only the keys defined by the second parameter. In this case, that parameter
  196. '("$.0123456789") defines characters that are valid for a currency but put this after the code
  197. '    If keyResponse = False Then
  198. '       KeyAscii = 0
  199. '    End If
  200.  
  201. Public Function CtrlValidate(KeyIn As Integer, ValidateString As String) As Boolean
  202. Dim ValidateList As String
  203. Dim KeyOut As Integer
  204.  
  205. If KeyIn = 8 Or KeyIn = 9 Then
  206.     CtrlValidate = True
  207.     Exit Function
  208. End If
  209. If InStr(1, ValidateString, Chr(KeyIn), 1) > 0 Then
  210.    CtrlValidate = True
  211. Else
  212.    CtrlValidate = False
  213.    Beep
  214. End If
  215. End Function
  216.  
  217. Public Function CheckCombo(SourceCombo As ComboBox, Optional FieldName As String, Optional TableName As String, Optional db As ADODB.Connection, Optional MsgLoad As Boolean) As Boolean
  218. On Error GoTo exit_function
  219. Dim i As Integer
  220. Dim Response As Integer
  221.  
  222. CheckCombo = True
  223.   
  224.   For i = 0 To SourceCombo.ListCount - 1
  225.     If SourceCombo.Text = SourceCombo.List(i) Then
  226.         CheckCombo = False
  227.     End If
  228.   Next
  229.   
  230. If CheckCombo = True And MsgLoad = True And SourceCombo.Text <> "" Then
  231.     Dim ADOnewRS As ADODB.Recordset
  232.     Response = MsgBox("This is a new input for " & fMainForm.ActiveForm.lblfields(SourceCombo.Index) & " , would you like to add it to the database?", vbYesNo, "Information")
  233.     If Response = vbYes Then
  234.         Select Case TableName
  235.         Case "[SYS Tax Group]"
  236.             frm_SYS_Setup_Tax_Group.CallByUser SourceCombo.Text
  237.             MsgBox "New data have been transferred to TAX GROUP, but you have to add more data and save it." & vbCr & "Then the data will be available to use after you click the refresh button", vbInformation, "Information"
  238.             SourceCombo.Text = SourceCombo.List(0)
  239.         Case "[LIST Payment Terms]"
  240.             frm_LIST_Payment_Terms.CallByUserPay SourceCombo.Text
  241.             MsgBox "New data have been transferred to PAY TERMS, but you have to add more data and save it." & vbCr & "Then the data will be available to use after you click the refresh button", vbInformation, "Information"
  242.             SourceCombo.Text = SourceCombo.List(0)
  243.         'Case "[EMP Employees]"
  244.         '    frm_SYS_Setup_Employee.CallByUserEmpID SourceCombo.Text
  245.         '    MsgBox "New data have been transferred to PAY TERMS, but you have to add more data and save it." & vbCr & "Then the data will be available to use after you click the refresh button", vbInformation, "Information"
  246.         '    SourceCombo.Text = SourceCombo.List(0)
  247.         Case "[LIST Payment Methods]"
  248.            Set ADOnewRS = New ADODB.Recordset
  249.            With ADOnewRS
  250.                 .Open "SELECT [LIST PAY Method],[Payment Terms] FROM [LIST Payment Methods] WHERE " & FieldName & "='" & SourceCombo.Text & "' AND [Payment Terms]='" & fMainForm.ActiveForm.cbPurchase(5).Text & "'", db, adOpenKeyset, adLockOptimistic, adCmdText
  251.                 If .RecordCount = 0 Then
  252.                     .AddNew
  253.                         ![LIST PAY Method] = SourceCombo.Text & ""
  254.                         ![Payment Terms] = fMainForm.ActiveForm.cbPurchase(5).Text
  255.                         SourceCombo.List(i) = SourceCombo.Text
  256.                     .Update
  257.                 End If
  258.                 .Close
  259.            End With
  260.            Set ADOnewRS = Nothing
  261.         Case Else 'Customer Type, Item Categories,Payment Methods,Shipping Methods,
  262.                   'Vendor Type, Recurring Type
  263.            Set ADOnewRS = New ADODB.Recordset
  264.            With ADOnewRS
  265.                 .Open "SELECT " & FieldName & " FROM " & TableName & " WHERE " & FieldName & "='" & SourceCombo.Text & "'", db, adOpenKeyset, adLockOptimistic, adCmdText
  266.                 If .RecordCount = 0 Then
  267.                     .AddNew
  268.                         .Fields("" & StripBrackets(FieldName) & "") = SourceCombo.Text & ""
  269.                         SourceCombo.List(i) = SourceCombo.Text
  270.                     .Update
  271.                 End If
  272.                 .Close
  273.            End With
  274.            Set ADOnewRS = Nothing
  275.         End Select
  276.     Else
  277.         SourceCombo.Text = SourceCombo.List(0)
  278.     End If
  279. ElseIf CheckCombo = True And MsgLoad = False Then
  280.     SourceCombo.Text = SourceCombo.List(0)
  281. ElseIf CheckCombo = False Then
  282.     Select Case TableName
  283.     Case "[LIST Shipping Methods]"
  284.         Set ADOnewRS = New ADODB.Recordset 'txtfields(27)
  285.         ADOnewRS.Open " Select [LIST SHIP Charge] FROM [LIST Shipping Methods] WHERE [LIST SHIP Method]='" & SourceCombo.Text & "'", db, adOpenKeyset, adLockReadOnly, adCmdText
  286.           If fMainForm.ActiveForm.txtFields(23).Enabled = True Then fMainForm.ActiveForm.txtFields(23).SetFocus
  287.           If ADOnewRS![LIST SHIP Charge] > 0 Then
  288.             fMainForm.ActiveForm.txtFields(23) = "Yes"
  289.             fMainForm.ActiveForm.txtFields(27) = FormatCurr(ADOnewRS![LIST SHIP Charge])
  290.           Else
  291.             fMainForm.ActiveForm.txtFields(23) = "No"
  292.             fMainForm.ActiveForm.txtFields(27) = "$0.00"
  293.           End If
  294.         ADOnewRS.Close
  295.         Set ADOnewRS = Nothing
  296.     Case "[SYS Tax Group]"
  297.         Set ADOnewRS = New ADODB.Recordset 'txtfields(27)
  298.         ADOnewRS.Open " Select [SYS TAXGRPD Tax ID] FROM [SYS Tax Group Detail] WHERE [SYS TAXGRPD Group ID]='" & SourceCombo.Text & "'", db, adOpenKeyset, adLockReadOnly, adCmdText
  299.         Dim CountPercent As Double
  300.         CountPercent = 0
  301.           If ADOnewRS.RecordCount > 0 Then
  302.                 Dim ADOSecondRS As ADODB.Recordset
  303.                 
  304.                 Do While Not ADOnewRS.EOF
  305.                   Set ADOSecondRS = New ADODB.Recordset
  306.                   ADOSecondRS.Open " Select [SYS TAX Percent] FROM [SYS Tax] WHERE [SYS TAX ID]='" & ADOnewRS![SYS TAXGRPD Tax ID] & "'", db, adOpenKeyset, adLockReadOnly, adCmdText
  307.                     CountPercent = CountPercent + CDbl(ADOSecondRS![SYS TAX Percent])
  308.                   ADOSecondRS.Close
  309.                   Set ADOSecondRS = Nothing
  310.                   ADOnewRS.MoveNext
  311.                 Loop
  312.           End If
  313.                   fMainForm.ActiveForm.txtFields(29).SetFocus
  314.                   If CountPercent > 0 Then
  315.                     fMainForm.ActiveForm.txtFields(29) = Format(CountPercent, "00.00")
  316.                   Else
  317.                     fMainForm.ActiveForm.txtFields(29) = "00.00"
  318.                   End If
  319.         ADOnewRS.Close
  320.         Set ADOnewRS = Nothing
  321.     End Select
  322. End If
  323.  
  324. exit_function:
  325. End Function
  326.  
  327. Public Function SumRecord(Searchee As String, TableName As String, db As ADODB.Connection, Optional WhereCriteria As String) As Variant
  328. 'This function use to SUM all of the selected record. It uses the ADO Access Method.
  329. Dim Currentdb As Boolean
  330. '
  331. Exit Function
  332.   'Dim db As ADODB.Connection
  333.   Currentdb = False
  334.   If db Is Nothing Then
  335.     Set db = New ADODB.Connection
  336.     db.CursorLocation = adUseServer
  337.     db.Open gblADOProvider
  338.     Currentdb = True
  339.   End If
  340.     'Then Open the Recordset
  341.     Dim ADOprimaryrs As ADODB.Recordset
  342.     Set ADOprimaryrs = New ADODB.Recordset
  343.     'Execute the Query
  344.     If IsMissing(WhereCriteria) Then
  345.         'ADOprimaryRS.Source = "Select " & Searchee & " From " & TableName
  346.         'Set ADOprimaryRS.ActiveConnection = con
  347.         ADOprimaryrs.Open "Select " & Searchee & " From " & TableName, db, adOpenKeyset, adLockReadOnly, adCmdText
  348.     Else
  349.         ADOprimaryrs.Open "Select " & Searchee & " From " & TableName & " Where " & WhereCriteria, db, adOpenKeyset, adLockReadOnly, adCmdText
  350.         'ADOprimaryRS.Requery
  351.         'ADOprimaryRS.Source = "Select " & Searchee & " From [" & TableName & "] Where " & WhereCriteria
  352.         'Debug.Print "Select " & Searchee & " From [" & TableName & "] Where " & WhereCriteria
  353.         'Set ADOprimaryRS.ActiveConnection = con
  354.         'ADOprimaryRS.Open
  355.     End If
  356.         
  357.     SumRecord = 0
  358.     If Not ADOprimaryrs.EOF Then ADOprimaryrs.MoveFirst
  359.     If ADOprimaryrs.RecordCount > 0 Then ADOprimaryrs.MoveFirst
  360.     
  361.     While Not ADOprimaryrs.EOF
  362.         If Not IsNull(ADOprimaryrs.Fields(0).Value) Then
  363.             SumRecord = SumRecord + CDbl(ADOprimaryrs.Fields(0).Value)
  364.         End If
  365.         ADOprimaryrs.MoveNext
  366.     Wend
  367.  
  368.     ADOprimaryrs.Close
  369.     Set ADOprimaryrs = Nothing
  370.     
  371.    If Currentdb = True Then
  372.     db.Close
  373.     Set db = Nothing
  374.    End If
  375. End Function
  376.  
  377. Public Function CountRecord(Searchee As String, TableName As String, db As ADODB.Connection, Optional WhereCriteria As String) As Variant
  378.    'This function duplicates the CountRecord function in access. It is written using the global connect strings set-up in
  379.    'the Sub-Main Function in the Main Access Module. It uses the ADO Access Method.
  380.    'Open the Connection
  381. Dim Currentdb As Boolean
  382.   Currentdb = False
  383.   If db Is Nothing Then
  384.     Set db = New ADODB.Connection
  385.     db.CursorLocation = adUseServer
  386.     db.Open gblADOProvider
  387.     Currentdb = True
  388.   End If
  389.     'Open the Recordset
  390.     Dim ADOprimaryrs As ADODB.Recordset
  391.     Set ADOprimaryrs = New ADODB.Recordset
  392.     'Set ADOprimaryRS.ActiveConnection = con
  393.     'filter and recordcount also perform the same way
  394.     If IsMissing(WhereCriteria) Then
  395.         ADOprimaryrs.Open "Select Count (" & Searchee & ")  From " & TableName, db, adOpenKeyset, adLockReadOnly, adCmdText
  396.     Else
  397.         ADOprimaryrs.Open "Select Count (" & Searchee & ")  From " & TableName & " Where " & WhereCriteria, db, adOpenKeyset, adLockReadOnly, adCmdText
  398.     End If
  399.     'Debug.Print "Select Count (" & Searchee & ")  From " & TableName & " Where " & WhereCriteria
  400.     'If IsNull(ADOprimaryRS.Fields(0).Value) Then
  401.     '    CountRecord = 0
  402.     'Else
  403.         'CountRecord = ADOprimaryrs.RecordCount 'ADOprimaryRS.Fields(0).Value
  404.     'End If
  405.     If IsNull(ADOprimaryrs.Fields(0).Value) Then
  406.         CountRecord = 0
  407.     Else
  408.         CountRecord = ADOprimaryrs.Fields(0).Value
  409.     End If
  410.     
  411.     ADOprimaryrs.Close
  412.     Set ADOprimaryrs = Nothing
  413.     
  414.    If Currentdb = True Then
  415.     db.Close
  416.     Set db = Nothing
  417.    End If
  418. End Function
  419.  
  420. Public Function LookRecord(Searchee As String, TableName As String, db As ADODB.Connection, Optional WhereCriteria As String) As Variant
  421.     'This function duplicates the LookRecord function in access. It is written using the global connect strings set-up in
  422.     'the Sub-Main Function in the Main Access Module. It uses the ADO Access Method.
  423.     'Open the Connection
  424. Dim Currentdb As Boolean
  425.   Currentdb = False
  426.   If db Is Nothing Then
  427.     Set db = New ADODB.Connection
  428.     db.CursorLocation = adUseServer
  429.     db.Open gblADOProvider
  430.     Currentdb = True
  431.   End If
  432.     'Open the Recordset
  433.     Dim ADOprimaryrs As ADODB.Recordset
  434.     Set ADOprimaryrs = New ADODB.Recordset
  435.     'Set ADOprimaryRS.ActiveConnection = con
  436.             
  437.     If WhereCriteria = "" Then
  438.          ADOprimaryrs.Open "Select (" & Searchee & ") From " & TableName, db, adOpenKeyset, adLockReadOnly, adCmdText
  439.     Else
  440.          ADOprimaryrs.Open "Select " & Searchee & " From " & TableName & " Where " & WhereCriteria, db, adOpenKeyset, adLockReadOnly, adCmdText
  441.     End If
  442.     
  443.     If ADOprimaryrs.RecordCount = 0 Then
  444.         MsgBox "The Database is Empty.", vbCritical, "Error"
  445.         LookRecord = " "
  446.         GoTo EmptyDB
  447.     End If
  448.     If IsNull(ADOprimaryrs.Fields("" & StripBrackets(Searchee) & "").Value) Then
  449.         LookRecord = " "
  450.     Else
  451.         LookRecord = ADOprimaryrs.Fields("" & StripBrackets(Searchee) & "").Value
  452.     End If
  453.     
  454. EmptyDB:
  455.     ADOprimaryrs.Close
  456.     Set ADOprimaryrs = Nothing
  457.     
  458.    If Currentdb = True Then
  459.     db.Close
  460.     Set db = Nothing
  461.    End If
  462. End Function
  463.  
  464. Public Function NZ(Check1 As Variant, Optional Check2 As Variant)
  465.     'This function duplicates the NZ function in access.
  466.     If IsNull(Check1) Then
  467.         If IsMissing(Check2) Then NZ = 0 Else NZ = Check2
  468.     Else
  469.         NZ = Check1
  470.     End If
  471.     
  472. End Function
  473.  
  474. Public Function AddBrackets(ObjName As String) As String
  475. 'this functions adds [] to object names that might need
  476. 'them because they have spaces in them
  477. If InStr(ObjName, " ") > 0 And Mid(ObjName, 1, 1) <> "[" Then
  478.     AddBrackets = "[" & ObjName & "]"
  479.   Else
  480.     AddBrackets = ObjName
  481.   End If
  482. End Function
  483.  
  484. Public Function StripBrackets(ObjName As String) As String
  485.   'this function strips the [] off of data objects
  486.   If Mid(ObjName, 1, 1) = "[" Then
  487.     StripBrackets = Mid(ObjName, 2, Len(ObjName) - 2)
  488.   Else
  489.     StripBrackets = ObjName
  490.   End If
  491.  
  492. End Function
  493.  
  494. Public Function StripFileName(rsFileName As String) As String
  495. 'this function strips the file name from a path\file string
  496.   'On Error Resume Next
  497.   Dim i As Integer
  498.  
  499.   For i = Len(rsFileName) To 1 Step -1
  500.     If Mid(rsFileName, i, 1) = "\" Then
  501.       Exit For
  502.     End If
  503.   Next
  504.  
  505.   StripFileName = Mid(rsFileName, 1, i - 1)
  506.  
  507. End Function
  508.  
  509. Public Function CheckNumberCHQ(ReadCheck As String, db As ADODB.Connection, Account As String, Optional CheckNumber As String) As String
  510. Dim CheckNo As String
  511. Dim rsBank As ADODB.Recordset
  512.     Set rsBank = New ADODB.Recordset
  513.       rsBank.Open "SELECT [BANK ACCT Next Check No] FROM [Bank Accounts] WHERE [BANK ACCT ID]='" & Account & "'", db, adOpenKeyset, adLockOptimistic, adCmdText
  514.       If rsBank.RecordCount = 0 Then
  515.         MsgBox "Bank account is not valid!", , "Error"
  516.         rsBank.Close
  517.         Set rsBank = Nothing
  518.         GoTo NoCheck
  519.       End If
  520. If CheckNumber = "" Then
  521.     CheckNo = rsBank![BANK ACCT Next Check No] & ""
  522. Else
  523.     CheckNo = CheckNumber
  524. End If
  525.  
  526. Select Case UCase(ReadCheck)
  527. Case "READ"
  528.     CheckNumber = CheckCheckNumber(Account, CheckNo, db, False)
  529.     CheckNumberCHQ = CheckNumber
  530.     rsBank![BANK ACCT Next Check No] = Str(Val(CheckNumber) + 1)
  531. Case "CHECK"
  532.     'samada CheckNumberCHQ= Found atau CheckNumberCHQ="Not Found"
  533.     CheckNumberCHQ = CheckCheckNumber(Account, CheckNo, db, True)
  534.     'CheckNumberCHQ = CheckNumber
  535.     'If CheckNumberCHQ = "Not Found" Then
  536.     '    rsBank![BANK ACCT Next Check No] = Str(Val(CheckNumber) + 1)
  537.     'End If
  538. Case "BACK"
  539.     rsBank![BANK ACCT Next Check No] = Str(Val(CheckNumber) - 1)
  540. End Select
  541.     rsBank.Update
  542.     rsBank.Close
  543.     Set rsBank = Nothing
  544. '013-3514255
  545. Exit Function
  546.  
  547. NoCheck:
  548.     CheckNumberCHQ = ""
  549.     ShowStatus False
  550. End Function
  551.  
  552. Public Function CheckCheckNumber(Account As String, CheckNumber As String, db As ADODB.Connection, Optional MustTrue As Boolean) As String
  553. CheckAgain:
  554.     If CheckDocument("SELECT [AP PAY Check No] FROM [AP Payment Header] WHERE [AP PAY Bank Account]='" & Account & "' AND [AP PAY Check No]='" & CheckNumber & "'", db, True) = True Then
  555.         'cek masih tidak digunakan
  556.         If MustTrue = True Then
  557.             CheckCheckNumber = "Not Found"
  558.             Exit Function
  559.         Else
  560.             CheckCheckNumber = Str(CheckNumber)
  561.         End If
  562.     Else
  563.         'cek sudah digunakan
  564.         If MustTrue = True Then
  565.             CheckCheckNumber = "Found"
  566.             Exit Function
  567.         Else
  568.             CheckNumber = Str(Val(CheckNumber) + 1)
  569.             GoTo CheckAgain
  570.         End If
  571.     End If
  572. End Function
  573.  
  574. Public Function CheckCreditLimit(CurrentRequest As Currency, txtFieldsCust As String, db As ADODB.Connection, Optional ShowCredit As Boolean) As Boolean
  575. 'repaired on 16/4/2000-razi '
  576.  
  577.   'Check Credit limit for this customer
  578.   Dim Limit#
  579.   Dim CurrentBalance#
  580.   Dim Response%
  581.   Limit# = LookRecord("[AR CUST Credit Limit]", "[AR Customer]", db, "[AR CUST Customer ID] = '" & txtFieldsCust & "'")
  582.   If Limit# > 0 Then
  583.     CurrentBalance# = LookRecord("[AR CUST Financial Period 1]", "[AR Customer]", db, "[AR CUST Customer ID] = '" & txtFieldsCust & "'")
  584.     CurrentBalance# = CurrentBalance# + CurrentRequest
  585.     If ShowCredit = False Then
  586.         If CurrentBalance# > Limit# Then
  587.           Response% = MsgBox("New balance will exceed " & txtFieldsCust & " credit limit!" & vbCr & vbCr & _
  588.           "Credit Limit            : " & FormatCurr(CCur(Limit#)) & vbCr & _
  589.           "Previous Balance : " & FormatCurr(CurrentBalance# - CurrentRequest) & vbCr & _
  590.           "New Request       : " & FormatCurr(CurrentRequest) & vbCr & vbCr & _
  591.           "Credit Balance      : " & FormatCurr(CCur(Limit# - CurrentBalance#)) & vbCr & vbCr & _
  592.           "Would you like to Continue?", vbYesNo, "Information")
  593.           If Response% = vbNo Then
  594.             CheckCreditLimit = False
  595.             Exit Function
  596.           End If
  597.         End If
  598.     Else
  599.         MsgBox txtFieldsCust & " Credit Limit Information." & vbCr & vbCr & _
  600.         "Credit Limit            : " & FormatCurr(CCur(Limit#)) & vbCr & _
  601.         "Previous Balance : " & FormatCurr(CurrentBalance# - CurrentRequest) & vbCr & _
  602.         "New Request       : " & FormatCurr(CurrentRequest) & vbCr & _
  603.         "Credit Balance      : " & FormatCurr(CCur(Limit# - CurrentBalance#)), vbInformation, "Credit Limit Information"
  604.     End If
  605.   Else
  606.         MsgBox "There is no credit limit for " & txtFieldsCust
  607.   End If
  608. CheckCreditLimit = True
  609. End Function
  610.  
  611. Public Function AcctBalance(RequestType As String, Accttype As String, db As ADODB.Connection, Optional ReqValue As Currency) As String
  612. Dim AcctName As String
  613.  
  614. Select Case UCase(RequestType)
  615. Case "BALANCE"
  616.     AcctBalance = NZ(LookRecord("[GL COA Account Balance]", "[GL Chart Of Accounts]", db, "[GL COA Account No] = '" & Accttype & "'"))
  617.     AcctBalance = FormatCurr(CCur(AcctBalance))
  618. Case "NAME"
  619.     AcctBalance = NZ(LookRecord("[GL COA Account Name]", "[GL Chart Of Accounts]", db, "[GL COA Account No] = '" & Accttype & "'"))
  620. Case "DIFFERENCE"
  621.     AcctBalance = NZ(LookRecord("[GL COA Account Balance]", "[GL Chart Of Accounts]", db, "[GL COA Account No] = '" & Accttype & "'"))
  622.     If CCur(AcctBalance) - ReqValue < 0 Then
  623.         AcctName = NZ(LookRecord("[GL COA Account Name]", "[GL Chart Of Accounts]", db, "[GL COA Account No] = '" & Accttype & "'"))
  624.         MsgBox AcctName & "(" & Accttype & ") available balance (" & FormatCurr(CCur(AcctBalance)) & _
  625.         ") is not enough to cover the request amount(" & FormatCurr(ReqValue) & ")"
  626.         AcctBalance = "Not Enough"
  627.     End If
  628. End Select
  629. End Function
  630.  
  631. Function PostGLWorkDetail(GLDate As Variant, GLNumber&, Optional db As ADODB.Connection)
  632.  
  633.   ''On Error Resume Next
  634.   Dim AccountPost$
  635.   Dim TranDate As Variant
  636.   Dim DebitAmount@
  637.   Dim CreditAmount@
  638.   Dim Success%
  639.   Dim Currentdb As Boolean
  640.   Dim SQLstatement As String
  641.   
  642.   Currentdb = False
  643.   'Dim db As ADODB.Connection
  644.   If db Is Nothing Then
  645.     Set db = New ADODB.Connection
  646.     db.CursorLocation = adUseClient
  647.     db.Open gblADOProvider
  648.     Currentdb = True
  649.   End If
  650.   
  651.   'Dim rsGLTransDetail As ADODB.Recordset
  652.   'Set rsGLTransDetail = New ADODB.Recordset
  653.   'rsGLTransDetail.Open "[GL Transaction Detail]", db, adOpenKeyset, adLockOptimistic, adCmdTable
  654.   
  655.   gLinesPosted% = 0
  656.  
  657.   ' exit if new GL # = 0
  658.   If GLNumber& = 0 Then Exit Function
  659.  
  660.   ' exit if GL Date isn't a date
  661.   If IsDate(GLDate) Then
  662.   Else
  663.     Exit Function
  664.   End If
  665.  
  666.   ' post GL Work to GL Trans
  667.   Dim DynaGL As ADODB.Recordset
  668.   Dim GLWorkDebitAmount@
  669.   Dim GLWorkCreditAmount@
  670.   Dim GlDebitTotal@
  671.   Dim GLCreditTotal@
  672.   Dim NewGLNumber&
  673.   
  674.   GlDebitTotal@ = 0
  675.   GLCreditTotal@ = 0
  676.  
  677.   Err = 0
  678.   
  679.   NewGLNumber& = 0
  680.   
  681.   ' create the dynaset summarized by Project & Account
  682.   Dim GotCountFlag As Integer
  683. FindAgain:
  684.   Set DynaGL = New ADODB.Recordset
  685.   DynaGL.Open "qrySumGLWorkDetail", db, adOpenKeyset, adLockReadOnly, adCmdTable
  686.       
  687.   If DynaGL.RecordCount = 0 Then
  688.     ' no data
  689.     GotCountFlag = MsgBox("Work is in Progress, Please Wait a Few second." & vbCr & "Stopping the process will cause an internal (Razi is still working on this)", vbYesNo, "Information")
  690.     If GotCountFlag = vbYes Then
  691.         DynaGL.Close
  692.         GoTo FindAgain
  693.     Else
  694.         GoTo Skip_PostGLWorkDetail
  695.     End If
  696.   Else
  697.     DynaGL.MoveFirst
  698.   ''On Error GoTo PostGLWork_Error
  699.     
  700.     NewGLNumber& = GLNumber&
  701.  
  702.     Do While DynaGL.EOF = False
  703.       If DynaGL("SumOfGW TRANSD Debit Amount") = DynaGL("SumOfGW TRANSD Credit Amount") Then
  704.         ' They negate each other so don't write them
  705.       Else
  706.         If DynaGL("SumOfGW TRANSD Debit Amount") > 0 And DynaGL("SumOfGW TRANSD Credit Amount") > 0 Then
  707.  
  708.           ' Process debit portion
  709.           GLWorkDebitAmount@ = DynaGL("SumOfGW TRANSD Debit Amount")
  710.           GLWorkCreditAmount@ = 0
  711.           '$
  712.           ' accumulate debit & credit totals
  713.           GlDebitTotal@ = GlDebitTotal@ + GLWorkDebitAmount@
  714.           GLCreditTotal@ = GLCreditTotal@ + GLWorkCreditAmount@
  715.     
  716.           ' write the gl detail
  717.           '-----------------------------------------------------
  718.           'rsGLTransDetail.AddNew
  719.           '  rsGLTransDetail("GL TRANSD Number") = NewGLNumber&
  720.           '  rsGLTransDetail("GL TRANSD Account") = CStr(DynaGL("GW TRANSD Account"))
  721.           '  rsGLTransDetail("GL TRANSD Debit Amount") = GLWorkDebitAmount@
  722.           '  rsGLTransDetail("GL TRANSD Credit Amount") = GLWorkCreditAmount@
  723.           '-----------------------------------------------------
  724.             If IsNull(DynaGL("GW TRANSD Project")) Then
  725.                 SQLstatement = "INSERT INTO [GL Transaction Detail]"
  726.                 SQLstatement = SQLstatement & " ([GL TRANSD Number],[GL TRANSD Account],[GL TRANSD Debit Amount],[GL TRANSD Credit Amount])"
  727.                 SQLstatement = SQLstatement & " VALUES (" & NewGLNumber& & ",'" & CStr(DynaGL("GW TRANSD Account")) & "'," & GLWorkDebitAmount@ & "," & GLWorkCreditAmount@ & ")"
  728.                 db.Execute SQLstatement
  729.             Else
  730.                 SQLstatement = "INSERT INTO [GL Transaction Detail]"
  731.                 SQLstatement = SQLstatement & " ([GL TRANSD Number],[GL TRANSD Account],[GL TRANSD Debit Amount],[GL TRANSD Credit Amount],[GL TRANSD Project])"
  732.                 SQLstatement = SQLstatement & " VALUES (" & NewGLNumber& & ",'" & CStr(DynaGL("GW TRANSD Account")) & "'," & GLWorkDebitAmount@ & "," & GLWorkCreditAmount@ & "," & CStr(DynaGL("GW TRANSD Project")) & ")"
  733.                 db.Execute SQLstatement
  734.                 'rsGLTransDetail("GL TRANSD Project") = CStr(DynaGL("GW TRANSD Project"))
  735.             End If
  736.           'rsGLTransDetail.Update
  737.           '-----------------------------------------------------
  738.   
  739.           ' post to the Chart of Accounts
  740.           AccountPost$ = DynaGL("GW TRANSD Account")
  741.           TranDate = DateValue(GLDate)
  742.           DebitAmount@ = GLWorkDebitAmount@
  743.           CreditAmount@ = GLWorkCreditAmount@
  744.           Success% = PostCOA(AccountPost$, TranDate, DebitAmount@, CreditAmount@, db)
  745.           
  746.           
  747.           ' Process credit portion
  748.           GLWorkDebitAmount@ = 0
  749.           GLWorkCreditAmount@ = DynaGL("SumOfGW TRANSD Credit Amount")
  750.           '
  751.           ' accumulate debit & credit totals
  752.           GlDebitTotal@ = GlDebitTotal@ + GLWorkDebitAmount@
  753.           GLCreditTotal@ = GLCreditTotal@ + GLWorkCreditAmount@
  754.     
  755.           ' write the gl detail
  756.           '------------------------------------------------------
  757.           'rsGLTransDetail.AddNew
  758.           '  rsGLTransDetail("GL TRANSD Number") = NewGLNumber&
  759.           '  rsGLTransDetail("GL TRANSD Account") = DynaGL("GW TRANSD Account") & ""
  760.           '  rsGLTransDetail("GL TRANSD Debit Amount") = GLWorkDebitAmount@
  761.           '  rsGLTransDetail("GL TRANSD Credit Amount") = GLWorkCreditAmount@
  762.           '  'rsGLTransDetail("GL TRANSD Project") = DynaGL("GW TRANSD Project") & ""
  763.           '  If IsNull(DynaGL("GW TRANSD Project")) Then
  764.           '  Else
  765.           '      rsGLTransDetail("GL TRANSD Project") = CStr(DynaGL("GW TRANSD Project"))
  766.           '  End If
  767.             If IsNull(DynaGL("GW TRANSD Project")) Then
  768.                 SQLstatement = "INSERT INTO [GL Transaction Detail]"
  769.                 SQLstatement = SQLstatement & " ([GL TRANSD Number],[GL TRANSD Account],[GL TRANSD Debit Amount],[GL TRANSD Credit Amount])"
  770.                 SQLstatement = SQLstatement & " VALUES (" & NewGLNumber& & ",'" & DynaGL("GW TRANSD Account") & "" & "'," & GLWorkDebitAmount@ & "," & GLWorkCreditAmount@ & ")"
  771.                 db.Execute SQLstatement
  772.             Else
  773.                 SQLstatement = "INSERT INTO [GL Transaction Detail]"
  774.                 SQLstatement = SQLstatement & " ([GL TRANSD Number],[GL TRANSD Account],[GL TRANSD Debit Amount],[GL TRANSD Credit Amount],[GL TRANSD Project])"
  775.                 SQLstatement = SQLstatement & " VALUES (" & NewGLNumber& & ",'" & DynaGL("GW TRANSD Account") & "" & "'," & GLWorkDebitAmount@ & "," & GLWorkCreditAmount@ & "," & CStr(DynaGL("GW TRANSD Project")) & ")"
  776.                 db.Execute SQLstatement
  777.                 'rsGLTransDetail("GL TRANSD Project") = CStr(DynaGL("GW TRANSD Project"))
  778.             End If
  779.           'rsGLTransDetail.Update
  780.           '------------------------------------------------------
  781.   
  782.           ' post to the Chart of Accounts
  783.           AccountPost$ = DynaGL("GW TRANSD Account")
  784.           TranDate = DateValue(GLDate)
  785.           DebitAmount@ = GLWorkDebitAmount@
  786.           CreditAmount@ = GLWorkCreditAmount@
  787.           Success% = PostCOA(AccountPost$, TranDate, DebitAmount@, CreditAmount@, db)
  788.           If Success% = False Then GoTo PostGLWork_Error
  789.           gLinesPosted% = gLinesPosted% + 1
  790.           '$
  791.         Else
  792.           If DynaGL("SumOfGW TRANSD Debit Amount") > DynaGL("SumOfGW TRANSD Credit Amount") Then
  793.             ' determine debit amount
  794.             GLWorkDebitAmount@ = DynaGL("SumOfGW TRANSD Debit Amount") - DynaGL("SumOfGW TRANSD Credit Amount")
  795.             GLWorkCreditAmount@ = 0
  796.           Else
  797.             ' determine credit amount
  798.             GLWorkDebitAmount@ = 0
  799.             GLWorkCreditAmount@ = DynaGL("SumOfGW TRANSD Credit Amount") - DynaGL("SumOfGW TRANSD Debit Amount")
  800.           End If
  801.   
  802.           ' accumulate debit & credit totals
  803.           GlDebitTotal@ = GlDebitTotal@ + GLWorkDebitAmount@
  804.           GLCreditTotal@ = GLCreditTotal@ + GLWorkCreditAmount@
  805.       
  806.           ' write the gl detail
  807.           '-------------------------------------------------------
  808.           'rsGLTransDetail.AddNew
  809.           '  rsGLTransDetail("GL TRANSD Number") = NewGLNumber&
  810.           '  rsGLTransDetail("GL TRANSD Account") = CStr(DynaGL("GW TRANSD Account"))
  811.           '  rsGLTransDetail("GL TRANSD Debit Amount") = GLWorkDebitAmount@
  812.           '  rsGLTransDetail("GL TRANSD Credit Amount") = GLWorkCreditAmount@
  813.           '  'rsGLTransDetail("GL TRANSD Project") = IIf(IsNull(DynaGL("GW TRANSD Project")), "", CStr(DynaGL("GW TRANSD Project")))
  814.           '  If IsNull(DynaGL("GW TRANSD Project")) Then
  815.           '  Else
  816.           '      rsGLTransDetail("GL TRANSD Project") = CStr(DynaGL("GW TRANSD Project"))
  817.           '  End If
  818.             If IsNull(DynaGL("GW TRANSD Project")) Then
  819.                 SQLstatement = "INSERT INTO [GL Transaction Detail]"
  820.                 SQLstatement = SQLstatement & " ([GL TRANSD Number],[GL TRANSD Account],[GL TRANSD Debit Amount],[GL TRANSD Credit Amount])"
  821.                 SQLstatement = SQLstatement & " VALUES (" & NewGLNumber& & ",'" & CStr(DynaGL("GW TRANSD Account")) & "'," & GLWorkDebitAmount@ & "," & GLWorkCreditAmount@ & ")"
  822.                 db.Execute SQLstatement
  823.             ElseIf CStr(DynaGL("GW TRANSD Project")) = "" Then
  824.                 SQLstatement = "INSERT INTO [GL Transaction Detail]"
  825.                 SQLstatement = SQLstatement & " ([GL TRANSD Number],[GL TRANSD Account],[GL TRANSD Debit Amount],[GL TRANSD Credit Amount])"
  826.                 SQLstatement = SQLstatement & " VALUES (" & NewGLNumber& & ",'" & CStr(DynaGL("GW TRANSD Account")) & "'," & GLWorkDebitAmount@ & "," & GLWorkCreditAmount@ & ")"
  827.                 db.Execute SQLstatement
  828.             Else
  829.                 SQLstatement = "INSERT INTO [GL Transaction Detail]"
  830.                 SQLstatement = SQLstatement & " ([GL TRANSD Number],[GL TRANSD Account],[GL TRANSD Debit Amount],[GL TRANSD Credit Amount],[GL TRANSD Project])"
  831.                 SQLstatement = SQLstatement & " VALUES (" & NewGLNumber& & ",'" & DynaGL("GW TRANSD Account") & "" & "'," & GLWorkDebitAmount@ & "," & GLWorkCreditAmount@ & "," & CStr(DynaGL("GW TRANSD Project")) & ")"
  832.                 db.Execute SQLstatement
  833.                 'rsGLTransDetail("GL TRANSD Project") = CStr(DynaGL("GW TRANSD Project"))
  834.             End If
  835.           'rsGLTransDetail.Update
  836.           '-------------------------------------------------------
  837.     
  838.           ' post to the Chart of Accounts
  839.           AccountPost$ = DynaGL("GW TRANSD Account")
  840.           TranDate = DateValue(GLDate)
  841.           DebitAmount@ = GLWorkDebitAmount@
  842.           CreditAmount@ = GLWorkCreditAmount@
  843.           Success% = PostCOA(AccountPost$, TranDate, DebitAmount@, CreditAmount@, db)
  844.           If Success% = False Then GoTo PostGLWork_Error
  845.           gLinesPosted% = gLinesPosted% + 1
  846.         End If
  847.       End If  'Accounts are equal
  848.       DynaGL.MoveNext
  849.     Loop
  850.   End If
  851.  
  852.     ' Update Gl Transaction Header
  853.   Dim rsGLTrans As ADODB.Recordset
  854. 'again:
  855.   Set rsGLTrans = New ADODB.Recordset
  856.   rsGLTrans.Open "SELECT [GL Trans Number],[GL Trans Amount] FROM [GL Transaction] WHERE [GL Trans Number]=" & NewGLNumber& & "", db, adOpenKeyset, adLockOptimistic, adCmdText
  857.   'MsgBox rsGLTrans.RecordCount
  858.   'rsGLTrans.MoveLast
  859.     If GlDebitTotal@ = GLCreditTotal@ Then
  860.         rsGLTrans("GL Trans Amount") = GlDebitTotal@
  861.         Else
  862.         rsGLTrans("GL Trans Amount") = 0
  863.     End If
  864.   rsGLTrans.Update
  865.   rsGLTrans.Close
  866.   Set rsGLTrans = Nothing
  867.  'GoTo again
  868.   PostGLWorkDetail = True
  869.   DynaGL.Close
  870.   Set DynaGL = Nothing
  871.   If Currentdb = True Then
  872.     db.Close
  873.     Set db = Nothing
  874.   End If
  875.   Exit Function
  876.  
  877. Skip_PostGLWorkDetail:
  878.  
  879.   DynaGL.Close
  880.   Set DynaGL = Nothing
  881.   If Currentdb = True Then
  882.     db.Close
  883.     Set db = Nothing
  884.   End If
  885.   ' End of post GL Work to GL Trans
  886.   PostGLWorkDetail = False
  887.   Exit Function
  888.  
  889. PostGLWork_Error:
  890.   MsgBox "Error"
  891.   DynaGL.Close
  892.   PostGLWorkDetail = False
  893.   Set DynaGL = Nothing
  894.   If Currentdb = True Then
  895.     db.Close
  896.     Set db = Nothing
  897.   End If
  898.  
  899.   Exit Function
  900.  
  901. End Function
  902.  
  903. Function PostCOA(Account$, TranDate As Variant, DebitAmount@, CreditAmount@, Optional db As ADODB.Connection) As Integer
  904.  
  905.   ''On Error Resume Next
  906.   
  907.   Dim AccountBalance@
  908.   Dim BalanceType$
  909.   Dim PeriodToPost%
  910.   Dim PeriodClosed%
  911.   Dim Post$
  912.   
  913.   If DebitAmount@ = 0 And CreditAmount@ = 0 Then
  914.     PostCOA% = True
  915.     Exit Function
  916.   End If
  917.  
  918. Dim Currentdb As Boolean
  919.   
  920.   'Dim db As ADODB.Connection
  921.   Currentdb = False
  922.   If db Is Nothing Then
  923.     Set db = New ADODB.Connection
  924.     db.CursorLocation = adUseServer
  925.     db.Open gblADOProvider
  926.     Currentdb = True
  927.   End If
  928.   Call VerifyPeriod(TranDate, PeriodToPost%, PeriodClosed%, db)
  929.   If PeriodToPost% = 0 Then
  930.     Post$ = 1
  931.   Else
  932.     Post$ = Trim$(Str(PeriodToPost%))
  933.   End If
  934.   
  935.   Dim rsGLCOA As ADODB.Recordset
  936.   Set rsGLCOA = New ADODB.Recordset
  937.  
  938.   'rsGLCOA.Open "SELECT * FROM [GL Chart Of Accounts] WHERE [GL COA Account No]=" & Account$, db, adOpenStatic, adLockOptimistic, adCmdText '<<<---3 seconds
  939.   rsGLCOA.Open "SELECT [GL COA Account No],[GL COA Balance Type]," & _
  940.   "[GL COA CY Period " & Post$ & " Amt],[GL COA Account Balance],[GL COA CY Beginning Amt] " & _
  941.   "FROM [GL Chart Of Accounts] WHERE [GL COA Account No]='" & Account$ & "'", db, adOpenKeyset, adLockOptimistic, adCmdText '<<<---3 seconds
  942.   
  943.   Post$ = Trim$(Str(PeriodToPost%))
  944.  
  945.   'rsGLCOA.Index = "PrimaryKey"
  946.   'rsGLCOA.Find "[GL COA Account No]=" & Account$
  947.   If rsGLCOA.RecordCount = 0 Then
  948.     PostCOA = False
  949.     Exit Function
  950.   Else
  951.   rsGLCOA.MoveFirst
  952.   
  953.     BalanceType$ = IIf(IsNull(rsGLCOA("GL COA Balance Type")), "Debit", rsGLCOA("GL COA Balance Type"))
  954.     
  955.     'Call VerifyPeriod(TranDate, PeriodToPost%, PeriodClosed%, db)
  956.     'Post$ = Trim$(Str(PeriodToPost%))
  957.  
  958.     ''On Error GoTo PostCOA_Error
  959.  
  960.     If PeriodToPost% > 0 Then
  961.       ' Post to Period
  962.         AccountBalance@ = IIf(IsNull(rsGLCOA("GL COA CY Period " & Post$ & " Amt")), 0, rsGLCOA("GL COA CY Period " & Post$ & " Amt"))
  963.         If DebitAmount@ <> 0 Then
  964.           rsGLCOA("GL COA Account Balance") = rsGLCOA("GL COA Account Balance") + DebitAmount@
  965.           rsGLCOA("GL COA CY Period " & Post$ & " Amt") = AccountBalance@ + DebitAmount@
  966.         End If
  967.         If CreditAmount@ <> 0 Then
  968.           rsGLCOA("GL COA Account Balance") = rsGLCOA("GL COA Account Balance") - CreditAmount@
  969.           rsGLCOA("GL COA CY Period " & Post$ & " Amt") = AccountBalance@ - CreditAmount@
  970.         End If
  971.       rsGLCOA.Update
  972.       ' end of post to period
  973.     Else
  974.       'Post to Beginning Balance Account
  975.         AccountBalance@ = IIf(IsNull(rsGLCOA("GL COA CY Beginning Amt")), 0, rsGLCOA("GL COA CY Beginning Amt"))
  976.         If DebitAmount@ <> 0 Then
  977.           rsGLCOA("GL COA Account Balance") = rsGLCOA("GL COA Account Balance") + DebitAmount@
  978.           rsGLCOA("GL COA CY Beginning Amt") = AccountBalance@ + DebitAmount@
  979.         End If
  980.         If CreditAmount@ <> 0 Then
  981.           rsGLCOA("GL COA Account Balance") = rsGLCOA("GL COA Account Balance") - CreditAmount@
  982.           rsGLCOA("GL COA CY Beginning Amt") = AccountBalance@ - CreditAmount@
  983.         End If
  984.       rsGLCOA.Update
  985.     End If
  986.   End If
  987.   
  988.   MatchBank db, Account$, CDbl(DebitAmount@), CDbl(CreditAmount@)
  989.   
  990.   PostCOA = True
  991.   rsGLCOA.Close
  992.   Set rsGLCOA = Nothing
  993.    If Currentdb = True Then
  994.     db.Close
  995.     Set db = Nothing
  996.    End If
  997.   
  998.   Exit Function
  999.  
  1000. PostCOA_Error:
  1001.   
  1002.   PostCOA = False
  1003.   rsGLCOA.Close
  1004.   Set rsGLCOA = Nothing
  1005.    If Currentdb = True Then
  1006.     db.Close
  1007.     Set db = Nothing
  1008.    End If
  1009.  
  1010.   Exit Function
  1011.  
  1012. End Function
  1013.  
  1014. Public Function FormatDate(RequestDate As Date, Optional DateType As String) As String
  1015. Select Case DateType
  1016. Case "MonthYear"
  1017.     FormatDate = Format(RequestDate, "mmmm yyyy")
  1018. Case "Long Date"
  1019.     FormatDate = Format(RequestDate, "Long Date")
  1020. Case "General Date"
  1021.     FormatDate = Format(RequestDate, "General Date")
  1022. Case "Medium Date"
  1023.     FormatDate = Format(RequestDate, "Medium Date")
  1024. Case "Short Date"
  1025.     FormatDate = Format(RequestDate, "Short Date")
  1026. Case Else
  1027.     FormatDate = Format(RequestDate, "mm/dd/yyyy")
  1028. End Select
  1029. End Function
  1030.  
  1031. Public Function FormatCurr(RequestCurr As Currency, Optional AcctStandard As Boolean) As String
  1032. If AcctStandard = True Then
  1033.     FormatCurr = Format(RequestCurr, "$###,###,###,##0.00")
  1034. Else
  1035.     FormatCurr = Format(RequestCurr, "$###,###,###,##0.00;($###,###,###,##0.00)")
  1036. End If
  1037. End Function
  1038.  
  1039. Public Function ValidatePower(DocumentNo As String, TransType As String, TransProcess As String, db As ADODB.Connection) As Boolean
  1040. Dim Power As String
  1041. Dim SQLstatement As String
  1042.  
  1043.   Power = LookRecord("[EMP Custom 1]", "[EMP Employees]", db, "[EMP ID] = '" & AppLoginName & "'")
  1044.   If CInt(Power) = 1 Then
  1045.       SQLstatement = "INSERT INTO [Transaction]"
  1046.       SQLstatement = SQLstatement & " ([Transaction ID],[Transaction Approved By],[Transaction Approved On],[Transaction Process],[Transaction Type])"
  1047.       SQLstatement = SQLstatement & " VALUES ('" & DocumentNo & "','" & AppLoginName & "',#" & Now & "#,'" & TransProcess & "','" & TransType & "')"
  1048.       db.Execute SQLstatement
  1049.       'Debug.Print SQLstatement
  1050.     ValidatePower = True
  1051.   Else
  1052.     MsgBox "You have no authority to approved this transaction", vbInformation, "Information"
  1053.     ValidatePower = False
  1054.   End If
  1055.  
  1056. End Function
  1057.