Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object variable or With block variable not set

Status
Not open for further replies.

djeeten

Programmer
Mar 13, 2003
59
BE
I keep getting this error & don't know how to handle it

this is my code:

----------------------------------------------
Private Sub cmdDelete_Click()

Dim con As Object
Dim stSql1 As String
Dim stSql2 As String
Dim stSql3 As String
Dim stSql4 As String

stSql1 = "UPDATE tblBudget SET Budget ='" & Me!Budget & "' + '" & Me!totalamount & "' WHERE CustomerId =" & Me!CustomerId
con.Execute (stSql4)

Set con = Application.CurrentProject.Connection
stSql2 = "UPDATE tblProductes INNER JOIN tblOrderlines ON tblProducts.ProductId = tblOrderlines.ProductId SET AmountInSupply = (AmountInSupply + LastAmount) WHERE tblOrderlines.OrderId =" & Me!OrderId
DoCmd.SetWarnings False
'Delete the order with its orderlines
stSql3 = "DELETE * FROM tblOrderlines where OrderId =" & Me!OrderId
stSql4 = "DELETE * FROM tblOrders where OrderId =" & Me!OrderId

DoCmd.SetWarnings True

Me.Refresh

con.Execute (stSql1)
con.Execute (stSql2)
con.Execute (stSql3)

DoCmd.Close
End Sub

-----------------------------------

I get the error while trying to update the table tblBudget.

As an order is cancelled by pressing the button cmdDelete, the budget of the customer has to be increased again with the total amount of the order(cfr. stSql1), but that's were something keeps going wrong.

Any idea why? Thanks a lot in advance,

dj.
 
try changing the order of the following two lines from your code

Code:
con.Execute (stSql4)

Set con = Application.CurrentProject.Connection

to

Code:
Set con = Application.CurrentProject.Connection

con.Execute (stSql4)
 
Also, you are executing statement4 (bad naming convention too.....) before you have set the string.

Craig
 
Thanks JustinEzequiel, that was a very stupid mistake I made. Sometimes I could just ... myself...

Craig0201, I'm sorry about my naming convention ;-), con.Execute (stSql4) was a typing error, it should have been stSql1. I had been changing just a bit too much of my code while putting it here (as I had to translate some things in English(not my native language)).

Thanks again!

dj.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top