I have an Access mdb which was created with a considerable amount of
development before the back end was switched to SQL Server. The
following code worked when the backend was Jet:
Problem now is that the form cannot see the PickID, so it cannot use
it to perform the insert statement into tblInventory. I get an ODBC
error. I have tried a few things which didn't work. What can I do
to allow my form to see the PickID which was just inserted into the
SQL table, tblPick?
Thanks in advance,
MrsBean
development before the back end was switched to SQL Server. The
following code worked when the backend was Jet:
Code:
Private Sub Form_AfterInsert()
On Error GoTo ErrorHandler
'Lookup record in inventory.
'if an inventory record with this pickid already exists, update it
'if it doesn't exist yet, add it to inventory
cmdSaveRec_Click
Dim ThisPick As Long
Dim strSQL As String
DoCmd.SetWarnings (0)
ThisPick = DCount("PickID", "tblInventory", "[PickID] = " &
Me.PickID)
If ThisPick = 1 Then
strSQL = "Update tblInventory set CatalogueID = " & Me.CatalogueID
& ", Quantity = (" & Me.QtyPicked & "* -1) where PickID = " &
Me.PickID
DoCmd.RunSQL strSQL
End If
If ThisPick = 0 Then
'insert a matching record for this PickID into inventory table
strSQL = "INSERT INTO tblInventory ( CatalogueID, Quantity, invDate,
PickID ) " & _
"SELECT " & Me.CatalogueID & " AS Expr1, (" & Me.QtyPicked & " * -1)
AS Expr2, #" & Now() & "# AS Expr3, " & Me.PickID & " as Expr4 ;"
Me.SQLStatement = strSQL
Me.SQLStatement.Requery
DoCmd.RunSQL strSQL
End If
DoCmd.SetWarnings (1)
ErrorHandlerExit:
Exit Sub
ErrorHandler:
msgbox err.number & " : " & err.message
Resume ErrorHandlerExit
End Sub
Problem now is that the form cannot see the PickID, so it cannot use
it to perform the insert statement into tblInventory. I get an ODBC
error. I have tried a few things which didn't work. What can I do
to allow my form to see the PickID which was just inserted into the
SQL table, tblPick?
Thanks in advance,
MrsBean