Discussion Locked

Access 2000 Error # 3061

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a Function named ?ArchLedger()? that works great when I hard code dates (#date#) and start it via the Immediate window. ArchLedger is called (call ArchLedger) from a button on a form named BkpgMgr that contains BeginArch (Date) and EndArch (Date) Fields. The query I used to create the code assigned to ?SqlStr? also works fine when I manually enter the required date range values. When I click the button on BkpgMgr I receive ?Error # 3061 was generated by DAO.Database Too few parameters. Expected 2.? The query contains ?Between[Forms]![BkpgMgr].[BeginArch] And [Forms]![BkpgMgr].[EndArch]? within the Criteria slot under the records Date field and as far as I can see this should work fine? I tried ActiveForm, Me, and everything else I think should work but consistently get the same #3061 error generated by Jet. As you can see my procedure is tied to the Tables (as it should be) and not a query ? I just built the query to test and because I?m lazy.

Function ArchLedger()'DEFINE A PROCEDURE TO POST GenLedger RECORDS INTO THE ArchLedger TABLE
'WHEN THE RECORDS FALL WITHIN A USER SPECIFIED DATE RANGE.

'ENABLE PROCEDURAL ERROR HANDLING.
On Error GoTo ArchLedger_Err

'DECLARE AND INITIALIZE THE CURRENT DATABASE AS THE DATABASE TO USE.
Dim DB As Database
Set DB = CurrentDb()

DoCmd.Hourglass True 'CONVERT THE CURSOR TO AN HOURGLASS.

'DECLARE TEMPORARY RECORDSET VARIABLES TO REPRESENT THE SOURCE AND TARGET OBJECTS.
Dim AGL As Recordset 'Object Model's "ArchLedger" (target) TABLE.
Dim GL As Recordset 'Object Model's "GenLedger" (source) TABLE.

'OPEN THE TARGET RECORDSET USED WITHIN THIS PROCEDURE.
Set AGL = DB.OpenRecordset("ArchLedger", dbOpenDynaset)

'DECLARE PROCEDURE STRING MANAGEMENT VARIABLES.
Dim SqlStr As String 'SQL Strings.
Dim MBstr As String 'Message Box Strings.

'OPEN THE DATE RANGE (SOURCE and/or DRIVER) RECORDSET USED WITHIN

6 replies

by donq

THIS PROCEDURE.
SqlStr = "SELECT GenLedger.* FROM GenLedger WHERE (((GenLedger.glDate) Between [Forms]![BkpgMgr].[BeginArch] And [Forms]![BkpgMgr].[EndArch])) ORDER BY GenLedger.glPK;"
Set GL = DB.OpenRecordset(Sqlstr, dbOpenDynaset) 'WITH UNRESTRICTED CURSOR MOVEMENT.

'FOR EACH GL RECORD THAT FALLS WITHIN THIS PROCEDURES DATE RANGE ADD A NEW "ArchLedger" RECORD
?AND DELETE THE NEWLY PASTED RECORD FROM THE GenLedger TABLE.
GL.MoveFirst
While Not GL.EOF
AGL.AddNew 'CREATE A NEW RECORD IN THE TARGET TABLE.

?POST VALUES FROM THE SELECTED SOURCE RECORDSET.
AGL!aglPK = Format("AGL" & Right(GL!glPK, 12)) 'CONVERT "GL" TO "AGL".
AGL!aglDate = GL!glDate
AGL!aglFKcoa = GL!glFKcoa
AGL!aglDesc = GL!glDesc
AGL!aglAmt = GL!glAmt
AGL!aglOAct1 = GL!glOAct1
AGL!aglOAmt1 = GL!glOAmt1
AGL!aglDAct1 = GL!glDAct1
AGL!aglDAmt1 = GL!glDAmt1
AGL!aglDAct2 = GL!glDAct2
AGL!aglDamt2 = GL!glDAmt2
AGL!aglLuid = GL!glLuid
AGL!aglUpd = GL!glUpd

'INSERT THIS RECORD INTO THE "ArchLedger" TABLE.
AGL.Update

'DELETE THE LAST GenLedger RECORD THAT WAS JUST ARCHIVED.
GL.Delete

'MOVE TO THE NEXT LEDGER RECORD WITHIN "GL" AND PROCEED.
GL.MoveNext
Wend

'LET THE USER KNOW THE LEDGER ENTRIES WERE SUCCESSFULLY ARCHIVED.
MsgBox "Currently specified General Ledger entries were successfully archived to ArchLedger and deleted from GenLedger."
DoCmd.Hourglass False 'CHANGE THE CURSOR BACK TO NORMAL.

'GRACEFULLY EXIT THE PROCEDURE WHEN THE ERROR CAN'T BE HANDLED INTERNALLY.
ArchLedger_Exit:
DoCmd.Hourglass False 'CHANGE THE CURSOR BACK TO NORMAL.
Exit Function

'DEFINE THE ERROR THAT OCCURED TO SEE IF IT CAN BE HANDLED INTERNALLY.
Dim Msg As String 'DECLARE AND ENABLE AN ERROR COMMUNICATION STRING.
ArchLedger

by peyison

Try resolving the date fields in the query string first:

SqlStr = "SELECT GenLedger.* FROM GenLedger WHERE GenLedger.glDate Between #" & [Forms]![BkpgMgr].[BeginArch] & "# And #" & [Forms]![BkpgMgr].[EndArch] & "# ORDER BY GenLedger.glPK"

I've also wrapped the dates in #'s. One benefit of doing it this way is that it's easier to test. Put a breakpoint after this assignment, run the code, and you can see the resolved select statement with the dates in place. You can then copy it and pasteit into the SQL window of a new query to test it.

Hope this helps.

by donq

When I delimited my Date calls as you suggested the query reports an error "The expression is typed incorrectly or is to complex to evaluate." and/or "The expression you entered has an invalid date value."

I then tried beginning with a quote("), and then equal quote (=") all to no avail.

I know the Date data type is OK because it performs perfectly everywhere else throught the application? Remember when I hard coded the dates within the pound sign everything within the procedure worked fine? Actually that's how I populated my table (ArchLedger)initially.

by peyison

The key is to do the string concatenation when setting strSql and setting a breakpoint so that you can actually test the resolved string. You need to be able to see what you're passing to OpenRecordset to see what it's complaining about.

by donq

I am so glad you communicated the second time - everything works fine now and the answer (as usual) is so simple and obvious. Mornings work better for me and a fresh look this AM took about 5 minutes - Thanks loads!

This discussion is closed to new replies.