I am trying to do this in VBA, but have been unsuccessful. I don't i may even be doing it wrong. I have search all over the site for an exampl of what I am tryin gto do.
When a user hits btnSave VBA decides whether to run an insert or update sql.
Right now the code stops at the DoCmd.RunSQL sSQL with the error:
"A RunSQL action requires an argument consisting of an SQL statement."
here is the code on the form:
Here is the functions (I like to have it in module so i can call these statements from anywhere)
I hope someone can help me.
When a user hits btnSave VBA decides whether to run an insert or update sql.
Right now the code stops at the DoCmd.RunSQL sSQL with the error:
"A RunSQL action requires an argument consisting of an SQL statement."
here is the code on the form:
Code:
Dim sSQL As String
sSQL = "SELECT * FROM tblDNclaims WHERE ClaimNo = " & Me.ClaimNo
DoCmd.RunSQL sSQL
Select Case sSQL
Case Is = Null
Call InsertDN(Me.ClaimNo, Me.DN_Date, Me.DNclerk, Me.CatCode, Me.DN_Reason)
Case Is <> Null
Call UpdateDN(Me.ClaimNo, Me.DN_Date, Me.DNclerk, Me.CatCode, Me.DN_Reason)
End Select
Here is the functions (I like to have it in module so i can call these statements from anywhere)
Code:
Public Function UpdateDN(uClaim As Long, uDate As Date, uClerk As String, uCatCode As String, uReason As String)
Dim uSQL As String
uSQL = "UPDATE tblDNclaims SET DN_Date = # uDate #, DNclerk = '" & uClerk & "', CatCode = '" & uCatCode & "', DN_Reason = '" & uReason & "' _ &"
WHERE "ClaimNo = " & uClaim
DoCmd.RunSQL uSQL
End Function
Code:
Public Function InsertDN(iClaim As Long, iDate As Date, iClerk As String, iCatCode As String, iReason As String)
Dim iSQL As String
iSQL = "INSERT INTO tblDNclaims (ClaimNo, DN_Date, DNclerk, CatCode, DN_Reason, TimeStamp) _ &"
VALUES "(iClaim, # iDate #, '" & iClerk & "', '" & iCatCode & "', '" & iReason & "')"
DoCmd.RunSQL iSQL
End Function
I hope someone can help me.