473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem with IF condition

101 100+
Hi,
My project is in MS Access 2002.Its on Inventory
In which I have one form, which I used for Shipping Data entry.

I am using this code

Expand|Select|Wrap|Line Numbers
  1. Private Sub Enter_Click()
  2. On Error GoTo Err_Enter_Click
  3.     Dim dbLocation
  4.     Dim sSQL
  5.     Dim sSQL1
  6.     dbLocation = "\\Cpfpidc01\FINISHED GOODS\Inventory.mdb"
  7.     Set objADO = CreateObject("ADODB.Connection")
  8.     objADO.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbLocation
  9.  
  10.     sSQL = "UPDATE PRODUCTION SET SHIPPEDDATE = '" & [Forms]![ShippingEntry]![SHIPPEDDATE] & "',ShippedQuantity = '" & [Forms]![ShippingEntry]![ShippedQuantity] & "',QTYONHAND = ((PRODUCTION.QTYONHAND)-('" & [Forms]![ShippingEntry]![ShippedQuantity] & "')),PackgingSlipNo = '" & [Forms]![ShippingEntry]![PackgingSlipNo] & "',Location = '" & [Forms]![ShippingEntry]![Location_Combo] & "',Notes = '" & [Forms]![ShippingEntry]![Notes] & "',Status = '" & [Forms]![ShippingEntry]![Location_Combo] & "' WHERE PalletNo='" & [Forms]![ShippingEntry]![PalletNo_Combo] & "'"
  11.  
  12.     objADO.Execute (sSQL)
  13.     MsgBox "All The Details saved Successfully."
  14.     objADO.Close
  15.     Set objADO = Nothing
  16. Exit_Enter_Click:
  17.     Exit Sub
  18. Err_Enter_Click:
  19.     MsgBox Err.Description
  20.     Resume Exit_Enter_Click
  21. End Sub


Now in this code I want to put like this

Expand|Select|Wrap|Line Numbers
  1. If((Forms!ShippingEntry!ShippedQuantity) = (PRODUCTION.TTlQuantity)) Then
  2. {
  3.     sSQL = "UPDATE PRODUCTION SET SHIPPEDDATE = '" & [Forms]![ShippingEntry]![SHIPPEDDATE] & "',ShippedQuantity = '" & [Forms]![ShippingEntry]![ShippedQuantity] & "',QTYONHAND = ((PRODUCTION.QTYONHAND)-('" & [Forms]![ShippingEntry]![ShippedQuantity] & "')),PackgingSlipNo = '" & [Forms]![ShippingEntry]![PackgingSlipNo] & "',Location = '" & [Forms]![ShippingEntry]![Location_Combo] & "',Notes = '" & [Forms]![ShippingEntry]![Notes] & "',Status = '" & [Forms]![ShippingEntry]![Location_Combo] & "' WHERE PalletNo='" & [Forms]![ShippingEntry]![PalletNo_Combo] & "'"
  4.  
  5. objADO.Execute (sSQL)
  6. }
  7. else 
  8. {
  9.     sSQL1 = "UPDATE PRODUCTION SET SHIPPEDDATE = '" & [Forms]![ShippingEntry]![SHIPPEDDATE] & "',ShippedQuantity = '" & [Forms]![ShippingEntry]![ShippedQuantity] & "',QTYONHAND = ((PRODUCTION.QTYONHAND)-('" & [Forms]![ShippingEntry]![ShippedQuantity] & "')),PackgingSlipNo = '" & [Forms]![ShippingEntry]![PackgingSlipNo] & "'',Notes = '" & [Forms]![ShippingEntry]![Notes] & "',Status = 'TOBESHIPPED' WHERE PalletNo='" & [Forms]![ShippingEntry]![PalletNo_Combo] & "'"
  10.  
  11.     objADO.Execute (sSQL1)
  12. }
But when i did that it shows error that

Object Require


What to do?
I think when I used Condition in IF, it require some recordset, which I not used in my code.
So please help me.
Jan 18 '08 #1
3 1197
jaxjagfan
254 Expert 100+
Hi,
My project is in MS Access 2002.Its on Inventory
In which I have one form, which I used for Shipping Data entry.

I am using this code

Expand|Select|Wrap|Line Numbers
  1. Private Sub Enter_Click()
  2. On Error GoTo Err_Enter_Click
  3.     Dim dbLocation
  4.     Dim sSQL
  5.     Dim sSQL1
  6.     dbLocation = "\\Cpfpidc01\FINISHED GOODS\Inventory.mdb"
  7.     Set objADO = CreateObject("ADODB.Connection")
  8.     objADO.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbLocation
  9.  
  10.     sSQL = "UPDATE PRODUCTION SET SHIPPEDDATE = '" & [Forms]![ShippingEntry]![SHIPPEDDATE] & "',ShippedQuantity = '" & [Forms]![ShippingEntry]![ShippedQuantity] & "',QTYONHAND = ((PRODUCTION.QTYONHAND)-('" & [Forms]![ShippingEntry]![ShippedQuantity] & "')),PackgingSlipNo = '" & [Forms]![ShippingEntry]![PackgingSlipNo] & "',Location = '" & [Forms]![ShippingEntry]![Location_Combo] & "',Notes = '" & [Forms]![ShippingEntry]![Notes] & "',Status = '" & [Forms]![ShippingEntry]![Location_Combo] & "' WHERE PalletNo='" & [Forms]![ShippingEntry]![PalletNo_Combo] & "'"
  11.  
  12.     objADO.Execute (sSQL)
  13.     MsgBox "All The Details saved Successfully."
  14.     objADO.Close
  15.     Set objADO = Nothing
  16. Exit_Enter_Click:
  17.     Exit Sub
  18. Err_Enter_Click:
  19.     MsgBox Err.Description
  20.     Resume Exit_Enter_Click
  21. End Sub


Now in this code I want to put like this

Expand|Select|Wrap|Line Numbers
  1. If((Forms!ShippingEntry!ShippedQuantity) = (PRODUCTION.TTlQuantity)) Then
  2. {
  3.     sSQL = "UPDATE PRODUCTION SET SHIPPEDDATE = '" & [Forms]![ShippingEntry]![SHIPPEDDATE] & "',ShippedQuantity = '" & [Forms]![ShippingEntry]![ShippedQuantity] & "',QTYONHAND = ((PRODUCTION.QTYONHAND)-('" & [Forms]![ShippingEntry]![ShippedQuantity] & "')),PackgingSlipNo = '" & [Forms]![ShippingEntry]![PackgingSlipNo] & "',Location = '" & [Forms]![ShippingEntry]![Location_Combo] & "',Notes = '" & [Forms]![ShippingEntry]![Notes] & "',Status = '" & [Forms]![ShippingEntry]![Location_Combo] & "' WHERE PalletNo='" & [Forms]![ShippingEntry]![PalletNo_Combo] & "'"
  4.  
  5. objADO.Execute (sSQL)
  6. }
  7. else 
  8. {
  9.     sSQL1 = "UPDATE PRODUCTION SET SHIPPEDDATE = '" & [Forms]![ShippingEntry]![SHIPPEDDATE] & "',ShippedQuantity = '" & [Forms]![ShippingEntry]![ShippedQuantity] & "',QTYONHAND = ((PRODUCTION.QTYONHAND)-('" & [Forms]![ShippingEntry]![ShippedQuantity] & "')),PackgingSlipNo = '" & [Forms]![ShippingEntry]![PackgingSlipNo] & "'',Notes = '" & [Forms]![ShippingEntry]![Notes] & "',Status = 'TOBESHIPPED' WHERE PalletNo='" & [Forms]![ShippingEntry]![PalletNo_Combo] & "'"
  10.  
  11.     objADO.Execute (sSQL1)
  12.  
  13.  
But when i did that it shows error that

Object Require


What to do?
I think when I used Condition in IF, it require some recordset, which I not used in my code.
So please help me.
sSQL1 not required. You are going to use just one or the other sql string and set sSQL to that value.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Enter_Click()
  2. On Error GoTo Err_Enter_Click
  3.     Dim dbLocation
  4.     Dim sSQL
  5.     dbLocation = "\\Cpfpidc01\FINISHED GOODS\Inventory.mdb"
  6.     Set objADO = CreateObject("ADODB.Connection")
  7.     objADO.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbLocation
  8.  
  9.  
  10. If((Forms!ShippingEntry!ShippedQuantity) = (PRODUCTION.TTlQuantity)) Then
  11.  
  12. sSQL = "UPDATE PRODUCTION SET SHIPPEDDATE = '" & [Forms]![ShippingEntry]![SHIPPEDDATE] & "',ShippedQuantity = '" & [Forms]![ShippingEntry]![ShippedQuantity] & "',QTYONHAND = ((PRODUCTION.QTYONHAND)-('" & [Forms]![ShippingEntry]![ShippedQuantity] & "')),PackgingSlipNo = '" & [Forms]![ShippingEntry]![PackgingSlipNo] & "',Location = '" & [Forms]![ShippingEntry]![Location_Combo] & "',Notes = '" & [Forms]![ShippingEntry]![Notes] & "',Status = '" & [Forms]![ShippingEntry]![Location_Combo] & "' WHERE PalletNo='" & [Forms]![ShippingEntry]![PalletNo_Combo] & "'"
  13.  
  14. ELSE 
  15.  
  16. sSQL = "UPDATE PRODUCTION SET SHIPPEDDATE = '" & [Forms]![ShippingEntry]![SHIPPEDDATE] & "',ShippedQuantity = '" & [Forms]![ShippingEntry]![ShippedQuantity] & "',QTYONHAND = ((PRODUCTION.QTYONHAND)-('" & [Forms]![ShippingEntry]![ShippedQuantity] & "')),PackgingSlipNo = '" & [Forms]![ShippingEntry]![PackgingSlipNo] & "'',Notes = '" & [Forms]![ShippingEntry]![Notes] & "',Status = 'TOBESHIPPED' WHERE PalletNo='" & [Forms]![ShippingEntry]![PalletNo_Combo] & "'"
  17.  
  18. End if
  19.  
  20.     objADO.Execute (sSQL)
  21.     MsgBox "All The Details saved Successfully."
  22.     objADO.Close
  23.     Set objADO = Nothing
  24. Exit_Enter_Click:
  25.     Exit Sub
  26. Err_Enter_Click:
  27.     MsgBox Err.Description
  28.     Resume Exit_Enter_Click
  29. End Sub
  30.  

Try that
Jan 18 '08 #2
billa856
101 100+
Sorry boss but this is not correct.

But Finaly I got my answer.

problem was in this following line

If((Forms!ShippingEntry!ShippedQuantity) = (PRODUCTION.TTlQuantity)) Then

but I finaly solve it and its like this

Private Sub Enter_Click()
On Error GoTo Err_Enter_Click
Dim dbLocation
Dim sSQL
Dim sSQL1
dbLocation = "\\CPFPIDC01\Users\APatel\Inventory.mdb"
Set objADO = CreateObject("ADODB.Connection")
objADO.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbLocation

If (Nz([Forms]![ShippingEntry]![ShippedQuantity], 0) < (DLookup("val(TTlQuantity)", "PRODUCTION", "PalletNo = '" & [Forms]![ShippingEntry]![PalletNo_Combo] & "'"))) Then

sSQL1 = "UPDATE PRODUCTION SET SHIPPEDDATE = '" & [Forms]![ShippingEntry]![SHIPPEDDATE] & "',ShippedQuantity = '" & [Forms]![ShippingEntry]![ShippedQuantity] & "',QTYONHAND = ((PRODUCTION.QTYONHAND)-('" & [Forms]![ShippingEntry]![ShippedQuantity] & "')),PackgingSlipNo = '" & [Forms]![ShippingEntry]![PackgingSlipNo] & "',Notes = '" & [Forms]![ShippingEntry]![Notes] & "',Status = 'TOBESHIPPED' WHERE PalletNo='" & [Forms]![ShippingEntry]![PalletNo_Combo] & "'"

objADO.Execute (sSQL1)
Else

sSQL = "UPDATE PRODUCTION SET SHIPPEDDATE = '" & [Forms]![ShippingEntry]![SHIPPEDDATE] & "',ShippedQuantity = '" & [Forms]![ShippingEntry]![ShippedQuantity] & "',QTYONHAND = ((PRODUCTION.QTYONHAND)-('" & [Forms]![ShippingEntry]![ShippedQuantity] & "')),PackgingSlipNo = '" & [Forms]![ShippingEntry]![PackgingSlipNo] & "',Location = '" & [Forms]![ShippingEntry]![Location_Combo] & "',Notes = '" & [Forms]![ShippingEntry]![Notes] & "',Status = '" & [Forms]![ShippingEntry]![Location_Combo] & "' WHERE PalletNo='" & [Forms]![ShippingEntry]![PalletNo_Combo] & "'"

objADO.Execute (sSQL)
End If
MsgBox "All The Details saved Successfully."

objADO.Close
Set objADO = Nothing

Exit_Enter_Click:
Exit Sub

Err_Enter_Click:
MsgBox Err.Description
Resume Exit_Enter_Click

End Sub


By the way thanks for ur reply
Jan 18 '08 #3
Delerna
1,134 Expert 1GB
One problem with the orriginal version of the if statements was the java syntax curly braces at lines 2, 6, 8, 12
and no end if
Jan 19 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
1
by: Joel | last post by:
As my registry start condition was working fine, now it's not working anymore Here are the kind of parameter I use in VSNEt2003: A) Registry : Name : Pipo; Property : PROP1; RegKey...
5
by: ???? | last post by:
this is an excerpt from C++ Primer 3rd edition by Lippman, Lajoie. How might we read an unknown number of input values? At the end of Section 1.2, we did just that. The code sequence string...
14
by: signaturefactory | last post by:
I am trying the following query in and oleDbCommand: SELECT PartLocations.LocationName, Sum(PartsJournal.Quantity) AS SumOfQuantity, PartsJournal.PartsLotNumber FROM PartLocations INNER JOIN...
4
by: phantom | last post by:
Hi All. I am having a problem writing to a file. I can successfully open the file and write the contents using fprintf, however if the writing is not done for a while in the process the file...
1
by: Sam Kong | last post by:
Hello! Recently I had a strange problem with Visual C# 2005 beta 1. When I ran(F5 key) a program, <#if DEBUG> statement was not working. It ran as RELEASE mode. So I had to manually define...
9
by: Tony | last post by:
I have an operator== overload that compares two items and returns a new class as the result of the comparison (instead of the normal bool) I then get an ambiguous operater compile error when I...
7
by: Kalpana | last post by:
Hi, As iam working on convertion of C#1.1 to 2.0. Iam facing a problem (screen is flickered) while opening and closing any artifacts. When i tried to debug it is througing ContextSwitchDeadlock...
14
by: abhishekkarnik | last post by:
Hi, I am trying to read an exe file and print it out character by character in hexadecimal format. The file goes something like this in hexadecimal 0x4d 0x5a 0x90 0x00 0x03 .... so on When I...
1
by: jesmi | last post by:
hi all i have a problem with my code.following is my code: Connection con = null; PreparedStatement stmt = null;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.