Private mlngAccountNumber As Long Private mstrAccountName As String Private mstrHeader As String Private mdblBalance As Double Private mstrAccountType As String Private mlngLastChequeNumber As Long Private mstrTaxCode As String Private mstrCurrencyCode As String Private mlngExchangeAccount As Long Private mstrInactiveAccount As String Private mstrAccountantLinkCode As String Private mstrBSBNumber As String Private mstrBankAccountNumber As String Private mstrBankAccountName As String Private mstrTradingName As String Private mstrCreateBankFile As String Private mstrBankCode As String Private mlngDirectEntryUserID As Long Private mstrSelfBalancing As String Private mstrDescription As String Private mstrCashFlowClassification As String Private mstrReportsSubTotal As String Private cn As ADODB.Connection Private mstrSQLDest As String Private mstrSQLArgs As String Private Const CLASS_NAME = "clsMYOBAccount" Public Sub CreateAccount() Dim cmd As ADODB.Command Dim strSQL As String 'On Error GoTo Proc_Err If cn Is Nothing Then If MYOBConnection Is Nothing Then Set MYOBConnection = New clsMYOBConnection End If If MYOBConnection.cn Is Nothing Then Set cn = MYOBConnection.CreateConnection Else Set cn = MYOBConnection.cn End If End If Set cmd = New ADODB.Command strSQL = "INSERT INTO Import_Accounts " DetermineDestinationFields ValidateRequiredFields If mstrSQLDest <> "" And mstrSQLArgs <> "" Then cn.BeginTrans strSQL = strSQL & "(" & mstrSQLDest & ") VALUES (" & mstrSQLArgs & ")" With cmd Set .ActiveConnection = cn .CommandText = strSQL .CommandType = adCmdText .Execute , , adExecuteNoRecords '.CommandText = "END TRANSACTION" .Execute , , adExecuteNoRecords End With cn.CommitTrans End If Proc_Exit: On Error Resume Next Set cmd.ActiveConnection = Nothing Set cmd = Nothing End Sub Public Function FindAccount(Optional strAccountNumber As String, _ Optional strAccountName As String) As Variant Dim rs As ADODB.Recordset Dim strSQL As String Dim strSQL1 As String Dim strSQL2 As String On Error GoTo Proc_Err If cn Is Nothing Then If MYOBConnection Is Nothing Then Set MYOBConnection = New clsMYOBConnection End If If MYOBConnection.cn Is Nothing Then Set cn = MYOBConnection.CreateConnection Else Set cn = MYOBConnection.cn End If End If Set rs = New ADODB.Recordset strSQL = "SELECT AccountID FROM MYOB.Accounts WHERE " strSQL1 = IIf(strAccountNumber = "", "", "AccountNumber = '" & strAccountNumber & "'") strSQL2 = IIf(strAccountName = "", "", IIf(strAccountNumber = "", "", " AND AccountName = '" & strAccountName & "'")) rs.Open strSQL & strSQL1 & strSQL2, cn, adOpenStatic, adLockReadOnly If Not (rs.BOF And rs.EOF) Then FindAccount = rs!AccountID Else FindAccount = Null End If Proc_Exit: On Error Resume Next rs.Close Set rs = Nothing Exit Function Proc_Err: DoCmd.Beep MsgBox Err.Number & vbCrLf & vbCrLf & Err.Description, vbOKOnly + vbExclamation, "Error" FindAccount = Null Resume Proc_Exit Resume End Function Public Sub Synchronise() Dim ws As DAO.Workspace Dim db As Database Dim rsAccess As DAO.Recordset Dim rsMYOB As ADODB.Recordset Dim strSQL As String Dim dte As Date On Error GoTo Proc_Err If cn Is Nothing Then If MYOBConnection Is Nothing Then Set MYOBConnection = New clsMYOBConnection End If If MYOBConnection.cn Is Nothing Then Set cn = MYOBConnection.CreateConnection Else Set cn = MYOBConnection.cn End If End If Set ws = DBEngine(0) Set db = CurrentDb Set rsMYOB = New ADODB.Recordset dte = Now ws.BeginTrans strSQL = "SELECT AccountID, AccountName, AccountNumber FROM MYOB.Accounts ORDER BY AccountNumber" rsMYOB.Open strSQL, cn, adOpenStatic, adLockReadOnly strSQL = "SELECT ActID, ActName FROM Accounts WHERE MYOBUploadDate IS NULL ORDER BY ActID" Set rsAccess = db.OpenRecordset(strSQL, dbOpenSnapshot) Do While Not rsAccess.EOF rsMYOB.Find "AccountNumber = '" & rsAccess!ActID & "'" If Not (rsMYOB.BOF And rsMYOB.EOF) Then strSQL = "UPDATE Accounts SET MYOBUpdatedDate = " & dte db.Execute strSQL, dbFailOnError End If rsAccess.MoveNext Loop ws.CommitTrans Proc_Exit: On Error Resume Next rsAccess.Close rsMYOB.Close Set rsAccess = Nothing Set rsMYOB = Nothing Set db = Nothing Exit Sub Proc_Err: DoCmd.Beep MsgBox "Error " & Err.Number & vbCrLf & Err.Description, vbOKOnly + vbExclamation, "Error" ws.Rollback Resume Proc_Exit Resume End Sub Private Sub DetermineDestinationFields() mstrSQLDest = mstrSQLDest & "AccountNumber," mstrSQLArgs = mstrSQLArgs & mlngAccountNumber & "," If mstrAccountName <> "" Then mstrSQLDest = mstrSQLDest & "AccountName," mstrSQLArgs = mstrSQLArgs & "'" & mstrAccountName & "'," End If If mstrHeader <> "" Then mstrSQLDest = mstrSQLDest & "Header," mstrSQLArgs = mstrSQLArgs & "'" & mstrHeader & "'," End If mstrSQLDest = mstrSQLDest & "Balance," mstrSQLArgs = mstrSQLArgs & mdblBalance & "," If mstrAccountType <> "" Then mstrSQLDest = mstrSQLDest & "AccountType," mstrSQLArgs = mstrSQLArgs & "'" & mstrAccountType & "'," End If If mlngLastChequeNumber <> 0 Then mstrSQLDest = mstrSQLDest & "LastChequeNumber," mstrSQLArgs = mstrSQLArgs & mlngLastChequeNumber & "," End If If mstrTaxCode <> "" Then mstrSQLDest = mstrSQLDest & "TaxCode," mstrSQLArgs = mstrSQLArgs & "'" & mstrTaxCode & "'," End If If mstrCurrencyCode <> "" Then mstrSQLDest = mstrSQLDest & "CurrencyCode," mstrSQLArgs = mstrSQLArgs & "'" & mstrCurrencyCode & "'," End If If mlngExchangeAccount <> 0 Then mstrSQLDest = mstrSQLDest & "LastExchangeAccount," mstrSQLArgs = mstrSQLArgs & mlngExchangeAccount & "," End If mstrSQLDest = mstrSQLDest & "InactiveAccount," If mstrInactiveAccount <> "" Then mstrSQLArgs = mstrSQLArgs & "'" & mstrInactiveAccount & "'," Else mstrSQLArgs = mstrSQLArgs & "'N'," End If If mstrAccountantLinkCode <> "" Then mstrSQLDest = mstrSQLDest & "AccountantLinkCode," mstrSQLArgs = mstrSQLArgs & "'" & mstrAccountantLinkCode & "'," End If If mstrBSBNumber <> "" Then mstrSQLDest = mstrSQLDest & "BSBNumber," mstrSQLArgs = mstrSQLArgs & "'" & mstrBSBNumber & "'," End If If mstrBankAccountName <> "" Then mstrSQLDest = mstrSQLDest & "BankAccountName," mstrSQLArgs = mstrSQLArgs & "'" & mstrBankAccountName & "'," End If If mstrTradingName <> "" Then mstrSQLDest = mstrSQLDest & "TradingName," mstrSQLArgs = mstrSQLArgs & "'" & mstrTradingName & "'," End If mstrSQLDest = mstrSQLDest & "CreateBankFile," If mstrCreateBankFile <> "" Then mstrSQLArgs = mstrSQLArgs & "'" & mstrCreateBankFile & "'," Else mstrSQLArgs = mstrSQLArgs & "'N'," End If If mstrBankCode <> "" Then mstrSQLDest = mstrSQLDest & "BankCode," mstrSQLArgs = mstrSQLArgs & "'" & mstrBankCode & "'," End If mstrSQLDest = mstrSQLDest & "DirectEntryUserID," mstrSQLArgs = mstrSQLArgs & mlngDirectEntryUserID & "," mstrSQLDest = mstrSQLDest & "SelfBalancing," If mstrSelfBalancing <> "" Then mstrSQLArgs = mstrSQLArgs & "'" & mstrSelfBalancing & "'," Else mstrSQLArgs = mstrSQLArgs & "'N'," End If If mstrDescription <> "" Then mstrSQLDest = mstrSQLDest & "Description," mstrSQLArgs = mstrSQLArgs & "'" & mstrDescription & "'," End If If mstrCashFlowClassification <> "" Then mstrSQLDest = mstrSQLDest & "CashFlowClassification," mstrSQLArgs = mstrSQLArgs & "'" & mstrCashFlowClassification & "'," End If If mstrReportsSubTotal <> "" Then mstrSQLDest = mstrSQLDest & "ReportsSubTotal," mstrSQLArgs = mstrSQLArgs & "'" & mstrReportsSubTotal & "'," End If 'Remove the trailing comma if it exists If mstrSQLDest <> "" Then mstrSQLDest = Left(mstrSQLDest, Len(mstrSQLDest) - 1) If mstrSQLArgs <> "" Then mstrSQLArgs = Left(mstrSQLArgs, Len(mstrSQLArgs) - 1) End Sub Private Sub ValidateRequiredFields() Dim strMessage As String Dim intError As Integer intError = 1 If mlngAccountNumber = 0 Then intError = 2 strMessage = "AccountNumber is missing." GoTo Proc_Err End If If mstrAccountName = "" Then intError = 2 strMessage = "AccountName is missing." GoTo Proc_Err End If Proc_Exit: Exit Sub Proc_Err: Err.Raise vbObjectError + intError, "ValidateRequiredFields", strMessage End Sub Private Sub Class_Initialize() InitializeVariables 'Set MYOBConnection = New clsMYOBConnection End Sub Private Sub Class_Terminate() On Error Resume Next cn.Close Set cn = Nothing End Sub Public Property Let AccountNumber(lngNewValue As Long) If lngNewValue < 0 Or lngNewValue > 99999 Then Err.Raise vbObjectError + 2, CLASS_NAME, GetErrorMessage(2) Exit Property End If mlngAccountNumber = lngNewValue End Property Public Property Get AccountNumber() As Long AccountNumber = mlngAccountNumber End Property Public Property Let AccountName(strNewValue As String) strNewValue = Replace(Replace(Trim(strNewValue), """", "''"), "'", "''") If Len(strNewValue) > 32 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property End If mstrAccountName = strNewValue End Property Public Property Get AccountName() As String AccountName = mstrAccountName End Property Public Property Let Header(strNewValue As String) strNewValue = Trim(strNewValue) If Len(strNewValue) > 1 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property ElseIf Len(strNewValue) = 1 And Val(strNewValue) <> 0 Then strNewValue = "1" Else strNewValue = "0" End If mstrHeader = strNewValue End Property Public Property Get Header() As String Header = mstrHeader End Property Public Property Let Balance(dblNewValue As Double) If dblNewValue < -9999999999999.99 Or dblNewValue > 9999999999999.99 Then Err.Raise vbObjectError + 2, CLASS_NAME, GetErrorMessage(2) Exit Property End If mdblBalance = dblNewValue End Property Public Property Get Balance() As Double Balance = mdblBalance End Property Public Property Let AccountType(strNewValue As String) strNewValue = Trim(strNewValue) If Len(strNewValue) > 23 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property Else 'If Asset Account: ' - Bank ' - Accounts Receivable ' - Other Current Asset ' - Fixed Asset ' - Other Asset 'If Liability Account: ' If Header: ' - Liability ' If non-Header: ' - Credit Card ' - Accounts Payable ' - Other Current Liability ' - Long Term Liability ' - Other Liability 'If Equity Account: ' - Equity 'If Income Account: ' - Income 'If Cost of Sale Account: ' - Cost of Sales 'If Expense Account: ' - Expense 'If Other Income Account: ' - Other Income 'If Other Expense Account: ' Other Expense End If mstrAccountType = strNewValue End Property Public Property Get AccountType() As String AccountType = mstrAccountType End Property Public Property Let LastChequeNumber(lngNewValue As Long) If lngNewValue < 0 Or lngNewValue > 9999999 Then Err.Raise vbObjectError + 2, CLASS_NAME, GetErrorMessage(2) Exit Property End If mlngLastChequeNumber = lngNewValue End Property Public Property Get LastChequeNumber() As Long LastChequeNumber = mlngLastChequeNumber End Property Public Property Let TaxCode(strNewValue As String) strNewValue = Trim(strNewValue) If Len(strNewValue) > 3 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property End If mstrTaxCode = strNewValue End Property Public Property Get TaxCode() As String TaxCode = mstrTaxCode End Property Public Property Let CurrencyCode(strNewValue As String) strNewValue = Trim(strNewValue) If Len(strNewValue) > 3 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property Else Select Case Asc(strNewValue) Case 38, 45, 46, 47, 65 To 90, 97 To 122 Case Else Err.Raise vbObjectError + 5, CLASS_NAME, GetErrorMessage(5) Exit Property End Select End If mstrCurrencyCode = strNewValue End Property Public Property Get CurrencyCode() As String CurrencyCode = mstrCurrencyCode End Property Public Property Let ExchangeAccount(lngNewValue As Long) If lngNewValue < 0 Or lngNewValue > 99999 Then Err.Raise vbObjectError + 2, CLASS_NAME, GetErrorMessage(2) Exit Property End If mlngExchangeAccount = lngNewValue End Property Public Property Get ExchangeAccount() As Long ExchangeAccount = mlngExchangeAccount End Property Public Property Let InactiveAccount(strNewValue As String) strNewValue = Trim(strNewValue) If Len(strNewValue) > 1 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property ElseIf Len(strNewValue) = 0 Then strNewValue = "N" ElseIf ((strNewValue <> "Y") And (strNewValue <> "N")) Then Err.Raise vbObjectError + 5, CLASS_NAME, GetErrorMessage(5) Exit Property End If mstrInactiveAccount = strNewValue End Property Public Property Get InactiveAccount() As String InactiveAccount = mstrInactiveAccount End Property Public Property Let AccountantLinkCode(strNewValue As String) strNewValue = Trim(strNewValue) If Len(strNewValue) > 9 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property End If mstrAccountantLinkCode = strNewValue End Property Public Property Get AccountantLinkCode() As String AccountantLinkCode = mstrAccountantLinkCode End Property Public Property Let BSBNumber(strNewValue As String) Dim intPos As Integer Dim intLeftNum As Integer Dim intRightNum As Integer If Len(strNewValue) > 7 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property ElseIf Not (strNewValue Like "###-###") Then Err.Raise vbObjectError + 6, CLASS_NAME, GetErrorMessage(6) Exit Property Else intPos = InStr(1, strNewValue, "-") If intPos = 0 Then Err.Raise vbObjectError + 7, CLASS_NAME, GetErrorMessage(7) Exit Property Else intLeftNum = Left(strNewValue, intPos - 1) intRightNum = Mid(strNewValue, intPos + 1) If (intLeftNum < 0 Or intLeftNum > 999) Or (intRightNum < 0 Or intRightNum > 999) Then Err.Raise vbObjectError + 2, CLASS_NAME, GetErrorMessage(2) Exit Property End If End If End If mstrBSBNumber = strNewValue End Property Public Property Get BSBNumber() As String BSBNumber = mstrBSBNumber End Property Public Property Let BankAccountNumber(strNewValue As String) strNewValue = Replace(Replace(Trim(strNewValue), """", "''"), "'", "''") If Len(strNewValue) > 20 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property End If mstrBankAccountNumber = strNewValue End Property Public Property Get BankAccountNumber() As String BankAccountNumber = mstrBankAccountNumber End Property Public Property Let BankAccountName(strNewValue As String) Dim intChar As Integer strNewValue = Replace(Replace(Trim(strNewValue), """", "''"), "'", "''") If Len(strNewValue) > 32 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property Else For intChar = 1 To Len(strNewValue) Select Case Asc(Mid(strNewValue, intChar, 1)) Case 38, 45, 46, 47, 65 To 90, 97 To 122 Case Else Err.Raise vbObjectError + 5, CLASS_NAME, GetErrorMessage(5) Exit Property End Select Next intChar End If mstrBankAccountName = strNewValue End Property Public Property Get BankAccountName() As String BankAccountName = mstrBankAccountName End Property Public Property Let TradingName(strNewValue As String) Dim intChar As Integer strNewValue = Replace(Replace(Trim(strNewValue), """", "''"), "'", "''") If Len(strNewValue) > 16 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property Else For intChar = 1 To Len(strNewValue) Select Case Asc(Mid(strNewValue, intChar, 1)) Case 38, 45, 46, 47, 65 To 90, 97 To 122 Case Else Err.Raise vbObjectError + 5, CLASS_NAME, GetErrorMessage(5) Exit Property End Select Next intChar End If mstrTradingName = strNewValue End Property Public Property Get TradingName() As String TradingName = mstrTradingName End Property Public Property Let CreateBankFile(strNewValue As String) strNewValue = Trim(strNewValue) If Len(strNewValue) > 1 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property ElseIf Len(strNewValue) = 0 Then strNewValue = "N" ElseIf ((strNewValue <> "Y") And (strNewValue <> "N")) Then Err.Raise vbObjectError + 5, CLASS_NAME, GetErrorMessage(5) Exit Property End If mstrCreateBankFile = strNewValue End Property Public Property Get CreateBankFile() As String CreateBankFile = mstrCreateBankFile End Property Public Property Let BankCode(strNewValue As String) strNewValue = Trim(strNewValue) If Len(strNewValue) > 3 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property Else Select Case Asc(strNewValue) Case 38, 45, 46, 47, 65 To 90, 97 To 122 Case Else Err.Raise vbObjectError + 5, CLASS_NAME, GetErrorMessage(5) Exit Property End Select End If mstrBankCode = strNewValue End Property Public Property Get BankCode() As String BankCode = mstrBankCode End Property Public Property Let DirectEntryUserID(lngNewValue As Long) If lngNewValue < 0 Or lngNewValue > 999999 Then Err.Raise vbObjectError + 2, CLASS_NAME, GetErrorMessage(2) Exit Property End If mlngDirectEntryUserID = lngNewValue End Property Public Property Get DirectEntryUserID() As Long DirectEntryUserID = mlngDirectEntryUserID End Property Public Property Let SelfBalancing(strNewValue As String) strNewValue = Trim(strNewValue) If Len(strNewValue) > 1 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property ElseIf Len(strNewValue) = 0 Then strNewValue = "N" ElseIf ((strNewValue <> "Y") And (strNewValue <> "N")) Then Err.Raise vbObjectError + 5, CLASS_NAME, GetErrorMessage(5) Exit Property End If mstrSelfBalancing = strNewValue End Property Public Property Get SelfBalancing() As String SelfBalancing = mstrSelfBalancing End Property Public Property Let Description(strNewValue As String) strNewValue = Replace(Replace(Trim(strNewValue), """", "''"), "'", "''") If Len(strNewValue) > 255 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property End If mstrDescription = strNewValue End Property Public Property Get Description() As String Description = mstrDescription End Property Public Property Let CashFlowClassification(strNewValue As String) strNewValue = Trim(strNewValue) If Len(strNewValue) > 1 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property Else Select Case strNewValue Case "F" 'Financing Case "I" 'Investing Case "O" 'Operating Case Else Err.Raise vbObjectError + 5, CLASS_NAME, GetErrorMessage(5) Exit Property End Select End If mstrCashFlowClassification = strNewValue End Property Public Property Get CashFlowClassification() As String CashFlowClassification = mstrCashFlowClassification End Property Public Property Let ReportsSubTotal(strNewValue As String) strNewValue = Trim(strNewValue) If Len(strNewValue) > 1 Then Err.Raise vbObjectError + 1, CLASS_NAME, GetErrorMessage(1) Exit Property ElseIf Len(strNewValue) = 0 Then strNewValue = "N" ElseIf ((strNewValue <> "Y") And (strNewValue <> "N")) Then Err.Raise vbObjectError + 5, CLASS_NAME, GetErrorMessage(5) Exit Property End If mstrReportsSubTotal = strNewValue End Property Public Property Get ReportsSubTotal() As String ReportsSubTotal = mstrReportsSubTotal End Property Sub InitializeVariables() 'This procedure exists only if needed in the future Exit Sub 'mlngAccountNumber As Long mstrAccountName = "" mstrHeader = "" 'mdblBalance As Double mstrAccountType = "" 'mlngLastChequeNumber As Long mstrTaxCode = "" mstrCurrencyCode = "" 'mlngExchangeAccount As Long mstrInactiveAccount = "" mstrAccountantLinkCode = "" mstrBSBNumber = "" mstrBankAccountNumber = "" mstrBankAccountName = "" mstrTradingName = "" mstrCreateBankFile = "" mstrBankCode = "" 'mlngDirectEntryUserID As Long mstrSelfBalancing = "" mstrDescription = "" mstrCashFlowClassification = "" mstrReportsSubTotal = "" End Sub