I'm using a Union query as a Source for an Append query. I will leave the code here. tblGLTransactions and tblGLTranaactionNo. I don't know if that is causing a problem. The tblGLTransactions has 2 fields, the fiest field GLTransactionNo is an autonumber
field, so I didn't append to that field. I need both tables because of the relationship for a form and subform for GLTransactions. The entry I'm trying to append closes the year end. Well, it should.
I should post the union query as well. I have drained out John Vinson who has been helping my like crazy in the past two days. This is the final step in completing this database and I cannoyt believe it crashes.
Here is the Union query ......I changed it. No AccountTypeID and no AcctgDate. IT's been modified for the extra fields. EDITED 09/12/11 12:51
SELECT qryYearEndReBalanceSheetTotals.AccountID, IIf([TotalTrans]<0,[TotalTrans]*-1,0) AS Debit, IIf([TotalTrans]>0,[TotalTrans],0) AS Credit, 0 AS GLTransactionNo, "Closing Entry" AS Source,qryYearEndReBalanceSheetTotals.TransDate FROM qryYearEndReBalanceSheetTotals
UNION ALL SELECT ([Forms]![frmYrEndProcessing]![cboRetainedEarnings]) AS AccountID, IIf([SumOfProfit]<0,[SumOfProfit],0) AS Debit, IIf([SumOfProfit]>0,[SumOfProfit],0) AS Credit, 0 AS GLTransactionNo, "Closing Entry" AS Source, DLookUp("FiscalYearEndDate","tblMyCompanyInfo")
AS TransDate FROM qryYearEndBalanceSheetProfit;
Here is the code: I created another query with GLTansactionNo and AcctgDate. The same 2 fields as the table. It still fails with the same Error 3061. Like the Title
Thanks for any help. this coded edited Sunday 09/12/11 12:54 pm
Private Sub cmdOkay_Click()
On Error GoTo ErrorHandler
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim lngID As Long
Dim strMessage As String
Dim IntMessageDialog As Integer
Dim strTitle As String
Dim intResult As Integer
If Me!chkPrintFinancials = False Then
MsgBox ("Print Financial Statements before Closing the Year End." & vbCrLf & _
"Ensure Start and Fiscal Year End Dates are not Blank in My Company Information Form.")
Else
If Nz(Me![cboRetainedEarnings].Value) = "" Then
MsgBox ("Choose an Account for Retained Earnings.")
End If
End If
If Not Me.chkPrintFinancials = False And Me.cboRetainedEarnings > -1 Then
Me.cmdCancelAndExit.Enabled = False
Else: Exit Sub
End If
DoCmd.Beep
strMessage = "Are you sure you want to Close the Year End?"
IntMessageDialog = vbQuestion + vbYesNo + vbDefaultButton1
strTitle = "Confirm Year End Close"
intResult = MsgBox(strMessage, IntMessageDialog, strTitle)
If intResult = vbNo Then
Exit Sub
End If
If intResult = vbYes Then
If IsNull(DLookup("FiscalYearEndDate", "tblMyCompanyInfo")) Then
MsgBox "Please fill in the fiscal year end date in the My Company info form", vbOKOnly
Exit Sub
Else
strSQL = "INSERT INTO [tblGLTransactions] ( AcctgDate) SELECT AcctgDate FROM " _
& "[qryYearEndGLTransactions] ;"
CurrentDb.Execute strSQL, dbFailOnError
lngID = DMax("GLTransactionNo", "tblGLTransactions")
strSQL = "INSERT INTO [tblTransactions] (TransDate, AccountID, Debit, Credit," _
& " Source, GLTransactionNo)" _
& "SELECT TransDate, AccountID, Debit, Credit," _
& "Source, " & lngID & " As GLTransactionNo FROM [qryuniYearEndFinalClosingEntry] ;"
CurrentDb.Execute strSQL, dbFailOnError
DBEngine(0)(0).Execute "qupdYearEndDateChanges", dbFailOnError
MsgBox ("The Year End is Processed.")
End If
End If
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "frmEnterGLTransactions"
DoCmd.GoToRecord , , acLast
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Debug.Print strSQL
Resume ErrorHandlerExit
End Sub