Adam McReynolds
Registered User.
- Local time
- Today, 02:32
- Joined
- Aug 6, 2012
- Messages
- 129
I have a button event that fires A SQL INSERT if the DCount is 0 and fires SQL UPDATE if DCount is 2. Something is wrong with the syntax because my INSERT will fire initially but upon a 2nd attempt it will not fire the UPDATE but rather the INSERT again even though there is RecordID that matches and should DCount 2. Here is my code for the button:
Any help would be appreciated.
P.S. The button is called by an AfterUpdate event in a datasheet form and RecordID is an autonumber and PaybackRecordID is a number.
Code:
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'INSERTS TO TABLES- If no record exsits
If DCount("PaybackRecordID", "TBL_ACTION", PaybackRecordID = " & Me.RecordID.Value & ") = 0 Then
'CUSTOMER OWED INSERT
'If OK then SQL INSERT Into Action Table
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO TBL_ACTION ([ActionEntity], [Action], [Qty], [StockType], [Notes], [TimeStamp], [PaybackRecordID]) Values ('" & Me.CustomerOwed & "', ""IN"", " & Me.PaybackLevel & ", '" & Me.StockType & "', '" & Me.Notes & "', Now(), " & Me.RecordID & ");"
DoCmd.SetWarnings True
Me.Refresh
'BORROWER CUSTOMER INSERT
'If OK then SQL INSERT Into Action Table
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO TBL_ACTION ([ActionEntity], [Action], [Qty], [StockType], [Notes], [TimeStamp],[PaybackRecordID]) Values ('" & Me.Borrower & "', ""OUT"", " & Me.PaybackLevel & ", '" & Me.StockType & "', '" & Me.Notes & "', Now(), " & Me.RecordID & " );"
DoCmd.SetWarnings True
Me.Refresh
Else
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'UPDATES TO TABLES- If record exsits
If DCount("PaybackRecordID", "TBL_ACTION", PaybackRecordID = " & Me.RecordID.Value & ") = 2 Then
'CUSTOMER OWED UPDATE
'If OK then SQL UPDATE Into Action Table
DoCmd.SetWarnings False
SQLupdate = "update TBL_ACTION set ([ActionEntity], [Action], [Qty], [StockType], [Notes], [TimeStamp]) = ('" & Me.CustomerOwed & "', ""IN"", " & Me.PaybackLevel & ", '" & Me.StockType & "', '" & Me.Notes & "', Now()) where PaybackRecordID = " & Me.RecordID & " AND ActionEntity = '" & Me.CustomerOwed & "';"
DoCmd.RunSQL SQLupdate
DoCmd.SetWarnings True
Me.Refresh
'BORROWER CUSTOMER UPDATE
'If OK then SQL UPDATE Into Action Table
DoCmd.SetWarnings False
SQLupdate = "update TBL_ACTION set ([ActionEntity], [Action], [Qty], [StockType], [Notes], [TimeStamp]) = ('" & Me.Borrower & "', ""OUT"", " & Me.PaybackLevel & ", '" & Me.StockType & "', '" & Me.Notes & "', Now()) where PaybackRecordID = " & Me.RecordID & " AND ActionEntity = '" & Me.Borrower & "';"
DoCmd.RunSQL SQLupdate
DoCmd.SetWarnings True
Me.Refresh
End If
End If
End Sub
Any help would be appreciated.
P.S. The button is called by an AfterUpdate event in a datasheet form and RecordID is an autonumber and PaybackRecordID is a number.