vb code runs append qry, raises err 3001?

S

sparkane

I have a routine (posted below), which allows users to create an order
by copying an old one. The routine raises error 3001 (invalid argument)
when it attepts to append the order line item records.

It appears that it's the query itself raising the error, because no
specific line in the routine immediately raises the error; rather, when
I step through the routine, it operates fine right through q.Execute,
and then steps through the functions called by the append query itself,
before failing.

However, when I run the line item append query by itself, it doesn't
fail.

I think the append query for the order header record also failed at
first in the same way; now it is working. It seemed to start working
after I decompiled the database. This hasn't worked for the second
append query, nor has compacting.

Thanks in advance. I'm also posting the two queries' SQL.

spark


<routine>
Public Function CopyItem( _
ByVal CopyID As Long, _
ByVal CopyKids As Boolean, _
ByVal EditCopy As Boolean) As Boolean
''
''
On Error GoTo HandleError

' CopyID is the order being copied, lNewOrdr is the new order's ID

Dim q As DAO.QueryDef
Dim p As DAO.Parameter
Dim p2 As DAO.Parameter
Dim lNewOrdr As Long
Dim r As DAO.Recordset
Dim s As String

'' Currently there is no editing copies. Copying an item will
'' immediately finish the Add New wizard. User can make adjustments
'' via the Detail View for the object in question.
If EditCopy Then
' nothing right now

Else
' Currently only Orders are copied, so this is specific to them.
' First copies order header record, then steps through any
' order detail/line item records.
' number.
If CopyID <> 0 Then
lNewOrdr = GetNextID(BOB_ORDER)

Set q = G_SESSION.DBDAO.QueryDefs("qaORDER_COPY")
Set p = q.Parameters!CopyID
Set p2 = q.Parameters!lNewID
p = CopyID
p2 = lNewOrdr
q.Execute

q.Close

If CopyKids Then
' Following gets list of line item IDs having parent
' order ID equal to CopyID (copied order ID)
s = "select fOLinID from qsORDERLINE " & _
"WHERE fOLinOrdr = " & CopyID
Set r = G_SESSION.DBDAO.OpenRecordset(s)
If Not r.EOF Then
r.MoveFirst

Do While Not r.EOF

Set q = G_SESSION.DBDAO.QueryDefs
("qaORDERLINE_COPY")
Set p = q.Parameters!CopyID
Set p2 = q.Parameters!lNewID
p = r.Fields("fOLinID").Value
p2 = lNewOrdr
q.Execute

r.MoveNext

Loop

Else
End If

Else
End If

Else
End If


End If

ExitProc:
On Error Resume Next
'CLEANUP CODE
Exit Function
HandleError:
ErrHandl.Rouse _
Err.Number, Err.Description, Err.Source, _
"cJobAddNew_CopyItem"

'' Select for further actions based on error number.
Select Case ErrHandl.ErrorNumber
Case Else
End Select

Resume ExitProc
End Function
</routine>

<qsORDER_COPY>
PARAMETERS CopyID Long, lNewID Long;
INSERT INTO TORDER ( fOrdrID, fOrdrName, fOrdrRepeat, fOrdrType,
fOrdrShipAddr, fOrdrBillAddr, fOrdrOpenDate, fOrdrDueBy, fOrdrStatus,
fOrdrSpecialInstr, fOrdrFlags, fOrdrAdded, fOrdrEdited, fOrdrAddSess,
fOrdrAddUser, fOrdrEdSess, fOrdrEdUser )
SELECT [lNewID] AS ID, qsORDER.fOrdrName AS Name, [CopyID] AS Repeat,
qsORDER.fOrdrType AS Type, qsORDER.fOrdrShipAddr AS ShipAddr,
qsORDER.fOrdrBillAddr AS BillAddr, Date() AS OpenDate, Date()+7 AS
DueBy, -1 AS Status, qsORDER.fOrdrSpecialInstr AS SpecialInstr,
qsORDER.fOrdrFlags AS Flags, Date() AS Added, Date() AS Edited,
GetSessionID() AS AddSess, CurrentUser() AS AddUser, GetSessionID() AS
EdSess, CurrentUser() AS EdUser
FROM qsORDER
WHERE (((qsORDER.fOrdrID)=[CopyID]));

<qsORDERLINE_COPY>
[The 'x's at the end of the select clause were functions like
CurrentUser, GetSessionID, etc]
PARAMETERS CopyID Long, lNewID Long;
INSERT INTO tOrderLine ( fOLinID, fOLinOrdr, fOLinSalb, fOLinType,
fOLinSize, fOLinStock, fOLinColor, fOLinPrints, fOLinArt, fOLinBindery,
fOLinMisc, fOLinQty, fOLinTotalPrice, fOLinStatus, fOLinFlags,
fOLinAdded, fOLinEdited, fOLinAddSess, fOLinAddUser, fOLinEdSess,
fOLinEdUser )
SELECT GetNextID(23) AS ID, [lNewID] AS Ordr, qsORDERLINE.fOLinSalb AS
Salb, qsORDERLINE.fOLinType AS Type, Nz([fOLinSize],"") AS [Size], Nz
([fOLinStock],"") AS Stock, Nz([fOLinColor],"") AS Color,
qsORDERLINE.fOLinPrints AS Prints, Nz([fOLinArt],"") AS Art, Nz
([fOLinBindery],"") AS Bindery, Nz([fOLinMisc],"") AS Misc,
qsORDERLINE.fOLinQty AS Qty, qsORDERLINE.fOLinTotalPrice AS TotalPrice,
-1 AS Status, Nz([fOLinFlags],"") AS Flags, Date() AS Added, Date() AS
Edited, "x" AS AddSess, "x" AS AddUser, "x" AS EdSess, "x" AS EdUser
FROM qsORDERLINE
WHERE (((qsORDERLINE.fOLinID)=[CopyID]));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top