The code below uses a query as a dataset. I have used this code in the past and it works fine. However, it is now generating a error [3001]: Invalid Arguement.
any suggestions would be appreaciate:
any suggestions would be appreaciate:
Code:
Private Sub Create_tblTempPO()
On Error GoTo Err_Hndlr
'**************************************************************
' this routine takes the data from groups the P0 tables' PO #
' and the PO line data. thereafter, it reads the recordset
' and writes only the first PO # with its first P0 Line
'**************************************************************
Dim rstGroupedPO As Recordset
Dim rsttblTempPO As Recordset
Dim strSQL As String
'**************************************************************
' temp fields for writing records
'**************************************************************
Dim strPR_ID_TEMP As String
Dim strPR_Date_TEMP As Date
'**************************************************************
' create output table
'**************************************************************
'Delete temporary table
'DoCmd.RunSQL "DROP TABLE tblTempPO;"
'**************************************************************
' initialize temporary fields
'**************************************************************
strFirstRec = "Yes"
'**************************************************************
' get to data to be analyzed
'**************************************************************
strSQL = "SELECT POData.[PO #], POData.[PR Line ID] FROM POData " & _
"GROUP BY POData.[PO #], POData.[PR Line ID];"
Set rstGroupedPO = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
'**************************************************************
' Create P0 table with only 1 PO Line ID
'**************************************************************
CurrentDb.Execute ("CREATE TABLE tblTempPO ([PO #] VARCHAR(10), [PR Line ID] int)")
'Bind rstSummary to the temporary table
Set rsttblTempPO = CurrentDb.OpenRecordset("tblTempPO")
rstGroupedPO.MoveFirst
Do While rstGroupedPO.EOF = False
If strFirstRec = "Yes" Then
strFirstRec = "No"
strPO_No_TEMP = " "
strPR_Line_ID_TEMP = "0"
End If
If rstGroupedPO![PO #] <> strPO_No_TEMP Then
If rstGroupedPO![PR Line ID] <> strPR_Line_ID_TEMP Then
'*** write record
rsttblTempPO.AddNew
rsttblTempPO![PO #] = strPR_ID_TEMP
rsttblTempPO![PR Line ID] = strPR_Date_TEMP
rstTotalDays.Update
'*** assign temp values
strPO_No_TEMP = rstGroupedPO![PO #]
strPR_Line_ID_TEMP = rstGroupedPO![PR Line ID]
End If
End If
rstGroupedPO.MoveNext
Loop
rstGroupedPO.Close
rsttblTempPO.Close
Create_tblTempPO_Exit:
Exit Sub
Err_Hndlr:
MsgBox "[" & Err.Number & "]: " & Err.Description, vbInformation, "Create_tblTempPO()"
End Sub
Comment