If - else error?

TheEvilSam

Registered User.
Local time
Today, 13:02
Joined
Jan 23, 2012
Messages
13
I have a query as follows
Code:
Private Sub StockOK_Click()
Dim SQLDelete1 As String
Dim SQLDelete2 As String
Dim SQLUpdate As String
Dim SQLStore As String

SQLDelete1 = "DELETE * FROM TblStock WHERE TblStock.ProductID = " & CboStockItem.Value
SQLDelete2 = "DELETE * FROM TblTotalSale WHERE TblTotalSale.ProductID = " & CboStockItem.Value
SQLUpdate = "INSERT INTO TblStock (ProductID, StockLevel) VALUES ( " & Me.CboStockItem.Value & "," & Me.TxtStockValue & " )"
SQLStore = "INSERT INTO TblSaleStore (ProductID, Item) VALUES ProductID, Item From TblTotalSale WHERE TblTotalSale.ProductID = " & CboStockItem.Value

If IsNull(Me.TxtStockValue) Then MsgBox "Please Select An Item To Update Stock And Ensure A Value Has Been Entered" Else:
DoCmd.RunSQL SQLDelete1
DoCmd.SetWarnings False
DoCmd.RunSQL SQLStore
DoCmd.RunSQL SQLDelete2
DoCmd.RunSQL SQLUpdate
DoCmd.SetWarnings True

End Sub
It all seems to work, but even when the value for the txt box is nul, it still continues with the doCmd bits. I only want the 6 lines of commands to run if the value is not null, but it keeps turning up error codes when the value is null.

Any Ideas?

Thanks

Sam

Ps, when not null, it is now saying there is a missing semicolon at the end of the SQLStore
 
Last edited:
edited the query to
Code:
SQLStore = "INSERT INTO TblSaleStore (ProductID) VALUES (TblTotalSale.ProductID) FROM TblTotalSale WHERE TblTotalSale.ProductID = " & Me.CboStockItem.Value
but still not working
 
I would test before running the code. This tests for both Null and a zero length string:

If Len(Me.SomeControl & vbNullString) = 0 Then
 

Users who are viewing this thread

Back
Top Bottom