473,386 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,386 software developers and data experts.

error message: "Else without if"

115 100+
I am trying to get the below statement work in VBA, but I always get the following error message: "Else without if"
Hope that someone help me ...
Expand|Select|Wrap|Line Numbers
  1. If (Qty < SolderieQty Or Qty = SolderieQty) Then
  2. If (Qty < sumq) Then
  3. MsgBox "check the Quantity. qty < sumq"
  4. Me.q1.SetFocus
  5. End If
  6. If (Qty > sumq) Then
  7. MsgBox "check the Quantity. qty > sumq"
  8. Me.q1.SetFocus
  9. End If
  10.  
  11. If (Qty = sumq) Then
  12. 'ADD the record into SendDetails table
  13. If ((Not IsNull(Article)) And (Not IsNull(sentdate)) And (Not IsNull(SendFrom)) And (Not IsNull(SendTo))) Then
  14.    MsgBox "first"
  15.  If (CheckIfSent(CLng(Forms![Transfer]!Article), CDate(Forms![Transfer]!send_Date), CStr(Forms![Transfer]!SendFrom), CStr(Forms![Transfer]!SendTo))) Then
  16.       MsgBox "you have sent this article before to the same location"
  17.       Forms![Transfer]![Article].SetFocus
  18.       MsgBox "aaaa"
  19.  Else
  20.  If (CheckIfSent(CLng(Forms![Transfer]!Article), CDate(Forms![Transfer]!send_Date), CStr(Forms![Transfer]!SendFrom), CStr(Forms![Transfer]!SendTo)) = False) Then
  21.     MsgBox "bbbb"
  22. InsertIntoSendDetails CDate(sentdate), CStr(SendFrom), CStr(SendTo), CLng(Article), CLng(Qty), CLng(q1), CLng(q2), _
  23. CLng(q3), CLng(q4), CLng(q5), CLng(q6), CLng(q7), CLng(q8), CLng(q9), CLng(q10), CLng(q11), CLng(q12), CLng(q13), CLng(q14) 'ADD TO WearHouseStock (st_house_qi) and MINUS FROM SolderieStock (st_sol_qi)
  24.  
  25. Me.st_q1.Value = (Nz(Me.st_q1.Value, 0) - Nz(Me.q1.Value, 0))
  26. Me.st_relax_q1.Value = (Nz(Me.st_relax_q1.Value, 0) + Nz(Me.q1.Value, 0))
  27. Me.st_q2.Value = (Nz(Me.st_q2.Value, 0) - Nz(Me.q2.Value, 0))
  28. Me.st_relax_q2.Value = (Nz(Me.st_relax_q2.Value, 0) + Nz(Me.q2.Value, 0))
  29. Me.st_q3.Value = (Nz(Me.st_q3.Value, 0) - Nz(Me.q3.Value, 0))
  30. Me.st_relax_q3.Value = (Nz(Me.st_relax_q3.Value, 0) + Nz(Me.q3.Value, 0))
  31. Me.st_q4.Value = (Nz(Me.st_q4.Value, 0) - Nz(Me.q4.Value, 0))
  32. Me.st_relax_q4.Value = (Nz(Me.st_relax_q4.Value, 0) + Nz(Me.q4.Value, 0))
  33. Me.st_q5.Value = (Nz(Me.st_q5.Value, 0) - Nz(Me.q5.Value, 0))
  34. Me.st_relax_q5.Value = (Nz(Me.st_relax_q5.Value, 0) + Nz(Me.q5.Value, 0))
  35. Me.st_q6.Value = (Nz(Me.st_q6.Value, 0) - Nz(Me.q6.Value, 0))
  36. Me.st_relax_q6.Value = (Nz(Me.st_relax_q6.Value, 0) + Nz(Me.q6.Value, 0))
  37. Me.st_q7.Value = (Nz(Me.st_q7.Value, 0) - Nz(Me.q7.Value, 0))
  38. Me.st_relax_q7.Value = (Nz(Me.st_relax_q7.Value, 0) + Nz(Me.q7.Value, 0))
  39. Me.st_q8.Value = (Nz(Me.st_q8.Value, 0) - Nz(Me.q8.Value, 0))
  40. Me.st_relax_q8.Value = (Nz(Me.st_relax_q8.Value, 0) + Nz(Me.q8.Value, 0))
  41. Me.st_q9.Value = (Nz(Me.st_q9.Value, 0) - Nz(Me.q9.Value, 0))
  42. Me.st_relax_q9.Value = (Nz(Me.st_relax_q9.Value, 0) + Nz(Me.q9.Value, 0))
  43. Me.st_q10.Value = (Nz(Me.st_q10.Value, 0) - Nz(Me.q10.Value, 0))
  44. Me.st_relax_q10.Value = (Nz(Me.st_relax_q10.Value, 0) + Nz(Me.q10.Value, 0))
  45. Me.st_q11.Value = (Nz(Me.st_q11.Value, 0) - Nz(Me.q11.Value, 0))
  46. Me.st_relax_q11.Value = (Nz(Me.st_relax_q11.Value, 0) + Nz(Me.q11.Value, 0))
  47. Me.st_q12.Value = (Nz(Me.st_q12.Value, 0) - Nz(Me.q12.Value, 0))
  48. Me.st_relax_q12.Value = (Nz(Me.st_relax_q12.Value, 0) + Nz(Me.q12.Value, 0))
  49. Me.st_q13.Value = (Nz(Me.st_q13.Value, 0) - Nz(Me.q13.Value, 0))
  50. Me.st_relax_q13.Value = (Nz(Me.st_relax_q13.Value, 0) + Nz(Me.q13.Value, 0))
  51. Me.st_q14.Value = (Nz(Me.st_q14.Value, 0) - Nz(Me.q14.Value, 0))
  52. Me.st_relax_q14.Value = (Nz(Me.st_relax_q14.Value, 0) + Nz(Me.q14.Value, 0))
  53. Me.SolderieStock.Value = (Nz(Me.SolderieStock.Value, 0) - Me.Qty.Value)
  54. Me.RelaxStock.Value = (Nz(Me.RelaxStock.Value, 0) + Me.Qty.Value)
  55. End If
  56. End If
  57. DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
  58. Else
  59. MsgBox "Qty entered more than the solderie stock quantity"
  60. Me.Qty.SetFocus
  61. End If
  62.  
Oct 6 '10 #1
4 2477
MMcCarthy
14,534 Expert Mod 8TB
The problem is at line#19 and line#20. Your code should look like this ...

Expand|Select|Wrap|Line Numbers
  1. If (Qty < SolderieQty Or Qty = SolderieQty) Then
  2.     If (Qty < sumq) Then
  3.         MsgBox "check the Quantity. qty < sumq"
  4.         Me.q1.SetFocus
  5.     End If
  6.  
  7.     If (Qty > sumq) Then
  8.         MsgBox "check the Quantity. qty > sumq"
  9.         Me.q1.SetFocus
  10.     End If
  11.  
  12.     If (Qty = sumq) Then
  13.         'ADD the record into SendDetails table
  14.         If ((Not IsNull(Article)) And (Not IsNull(sentdate)) And (Not IsNull(SendFrom)) And (Not IsNull(SendTo))) Then
  15.             MsgBox "first"
  16.             If (CheckIfSent(CLng(Forms![Transfer]!Article), CDate(Forms![Transfer]!send_Date), CStr(Forms![Transfer]!SendFrom), CStr(Forms![Transfer]!SendTo))) Then
  17.                   MsgBox "you have sent this article before to the same location"
  18.                   Forms![Transfer]![Article].SetFocus
  19.                   MsgBox "aaaa"
  20.             ElseIf (CheckIfSent(CLng(Forms![Transfer]!Article), CDate(Forms![Transfer]!send_Date), CStr(Forms![Transfer]!SendFrom), CStr(Forms![Transfer]!SendTo)) = False) Then
  21.                 MsgBox "bbbb"
  22.                 InsertIntoSendDetails CDate(sentdate), CStr(SendFrom), CStr(SendTo), CLng(Article), CLng(Qty), CLng(q1), CLng(q2), _
  23.                     CLng(q3), CLng(q4), CLng(q5), CLng(q6), CLng(q7), CLng(q8), CLng(q9), CLng(q10), CLng(q11), CLng(q12), CLng(q13), CLng(q14) 'ADD TO WearHouseStock (st_house_qi) and MINUS FROM SolderieStock (st_sol_qi)
  24.  
  25.                 Me.st_q1.Value = (Nz(Me.st_q1.Value, 0) - Nz(Me.q1.Value, 0))
  26.                 Me.st_relax_q1.Value = (Nz(Me.st_relax_q1.Value, 0) + Nz(Me.q1.Value, 0))
  27.                 Me.st_q2.Value = (Nz(Me.st_q2.Value, 0) - Nz(Me.q2.Value, 0))
  28.                 Me.st_relax_q2.Value = (Nz(Me.st_relax_q2.Value, 0) + Nz(Me.q2.Value, 0))
  29.                 Me.st_q3.Value = (Nz(Me.st_q3.Value, 0) - Nz(Me.q3.Value, 0))
  30.                 Me.st_relax_q3.Value = (Nz(Me.st_relax_q3.Value, 0) + Nz(Me.q3.Value, 0))
  31.                 Me.st_q4.Value = (Nz(Me.st_q4.Value, 0) - Nz(Me.q4.Value, 0))
  32.                 Me.st_relax_q4.Value = (Nz(Me.st_relax_q4.Value, 0) + Nz(Me.q4.Value, 0))
  33.                 Me.st_q5.Value = (Nz(Me.st_q5.Value, 0) - Nz(Me.q5.Value, 0))
  34.                 Me.st_relax_q5.Value = (Nz(Me.st_relax_q5.Value, 0) + Nz(Me.q5.Value, 0))
  35.                 Me.st_q6.Value = (Nz(Me.st_q6.Value, 0) - Nz(Me.q6.Value, 0))
  36.                 Me.st_relax_q6.Value = (Nz(Me.st_relax_q6.Value, 0) + Nz(Me.q6.Value, 0))
  37.                 Me.st_q7.Value = (Nz(Me.st_q7.Value, 0) - Nz(Me.q7.Value, 0))
  38.                 Me.st_relax_q7.Value = (Nz(Me.st_relax_q7.Value, 0) + Nz(Me.q7.Value, 0))
  39.                 Me.st_q8.Value = (Nz(Me.st_q8.Value, 0) - Nz(Me.q8.Value, 0))
  40.                 Me.st_relax_q8.Value = (Nz(Me.st_relax_q8.Value, 0) + Nz(Me.q8.Value, 0))
  41.                 Me.st_q9.Value = (Nz(Me.st_q9.Value, 0) - Nz(Me.q9.Value, 0))
  42.                 Me.st_relax_q9.Value = (Nz(Me.st_relax_q9.Value, 0) + Nz(Me.q9.Value, 0))
  43.                 Me.st_q10.Value = (Nz(Me.st_q10.Value, 0) - Nz(Me.q10.Value, 0))
  44.                 Me.st_relax_q10.Value = (Nz(Me.st_relax_q10.Value, 0) + Nz(Me.q10.Value, 0))
  45.                 Me.st_q11.Value = (Nz(Me.st_q11.Value, 0) - Nz(Me.q11.Value, 0))
  46.                 Me.st_relax_q11.Value = (Nz(Me.st_relax_q11.Value, 0) + Nz(Me.q11.Value, 0))
  47.                 Me.st_q12.Value = (Nz(Me.st_q12.Value, 0) - Nz(Me.q12.Value, 0))
  48.                 Me.st_relax_q12.Value = (Nz(Me.st_relax_q12.Value, 0) + Nz(Me.q12.Value, 0))
  49.                 Me.st_q13.Value = (Nz(Me.st_q13.Value, 0) - Nz(Me.q13.Value, 0))
  50.                 Me.st_relax_q13.Value = (Nz(Me.st_relax_q13.Value, 0) + Nz(Me.q13.Value, 0))
  51.                 Me.st_q14.Value = (Nz(Me.st_q14.Value, 0) - Nz(Me.q14.Value, 0))
  52.                 Me.st_relax_q14.Value = (Nz(Me.st_relax_q14.Value, 0) + Nz(Me.q14.Value, 0))
  53.                 Me.SolderieStock.Value = (Nz(Me.SolderieStock.Value, 0) - Me.Qty.Value)
  54.                 Me.RelaxStock.Value = (Nz(Me.RelaxStock.Value, 0) + Me.Qty.Value)
  55.             End If
  56.         End If
  57.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
  58. Else
  59.     MsgBox "Qty entered more than the solderie stock quantity"
  60.     Me.Qty.SetFocus
  61. End If
Oct 6 '10 #2
dsatino
393 256MB
You should also get out of the practice of using embedded IF...Then statements and use Select Case where possible.

Also, you had the forsight to name your controls sequentially so why not use that and reduce the amount of code?

Add this to the beginning of the procedure:

Expand|Select|Wrap|Line Numbers
  1. Dim xLoop as Integer
  2.  
And then replace lines 25 through 52 with this:

Expand|Select|Wrap|Line Numbers
  1. For xLoop = 1 to 14
  2.    Me.Controls("st_q" & xLoop).Value = (Nz(Me.Controls("st_q" & xLoop).Value, 0) - Nz(Me.Controls("q" & xLoop).Value, 0)) 
  3.  
  4.    Me.Controls("st_relax_q" & xLoop).Value = (Nz(Me.Controls("st_relax_q" & xLoop).Value, 0) + Nz(Me.Controls("q" & xLoop).Value, 0)) 
  5. Next
  6.  
Oct 7 '10 #3
NeoPa
32,556 Expert Mod 16PB
Notice that Mary's code is not only without the error that's in yours, it's also properly indented so that it's much easier to see such a problem before you even try to compile it. I suggest you use this format for all your code in future and have fewer problems as a result.

PS. DSatino's comments are also worth considering even if Mary has found and fixed your actual problem.
Oct 7 '10 #4
ADezii
8,834 Expert 8TB
Here is another Version of dsatino's explanation in Post# 3, which you may/may not find easier to understand and implement:
Expand|Select|Wrap|Line Numbers
  1. Dim bytCtrlCtr As Integer
  2. Dim ctl1 As Control
  3. Dim ctl2 As Control
  4. Dim ctl3 As Control
  5.  
  6. For bytCtrlCtr = 1 To 14
  7.   Set ctl1 = Me.Controls("st_q" & CStr(bytCtrlCtr))
  8.   Set ctl2 = Me.Controls("q" & CStr(bytCtrlCtr))
  9.   Set ctl3 = Me.Controls("st_relax_q" & CStr(bytCtrlCtr))
  10.  
  11.   ctl1 = (Nz(ctl1, 0) - Nz(ctl2, 0))
  12.   ctl3 = (Nz(ctl3, 0) + Nz(ctl2, 0))
  13. Next
Oct 7 '10 #5

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

Similar topics

40
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the...
1
by: zhangyuewuliu | last post by:
Hi, I have a DCOM Server and client running on the same box. I am using the custom security instead of default security and have opened up the server's custom access right to basically everyone. ...
0
by: Dirk Försterling | last post by:
Hi all, a few days ago, I upgraded from PostgreSQL 7.2.1 to 7.4, following the instructions in the INSTALL file, including dump and restore. All this worked fine without any error (message). ...
3
by: Paul | last post by:
I have an Access 2000 database with a form that is giving me some major headaches. When you open the form, it displays all records and allows editing, but has AllowAdditions set to False so that...
0
by: The Last Danish Pastry | last post by:
A couple of days ago there was a thread "Returning the machine epsilon". The responses in that thread suggested using Double.Epsilon or Single.Epsilon. Since both these seem to return zero I...
1
by: Robert Halford | last post by:
On 4th May at 7.45 in the evening my asp.net web sites stopped working on my development server. The page that appears says: Server Application Unavailable The web application you are...
1
by: Nick Ward | last post by:
Hey, I'm writing an app using C# visual studio express edition. When i run it in debug mode it runs fine and works perfectly, but when i run it without debugging (or from explorer) it crashes and...
3
by: AnalogKid17 | last post by:
I have the following line of code in my start/login page: document.getElementById("txtLogin").focus(); When I run the website app through F5 (Debug, Start Debugging) it works fine (ie, focus...
7
by: DC | last post by:
Hi, there is a 500;13 page one can configure in the website properties, but ..Net Framework 1.1 also delivers the "server too busy" message sometimes and the IIS custom error page does not seem...
4
by: robert | last post by:
On a server the binary (red hat) installed python2.4 and also a fresh compiled python2.5 spits "sem_post: Invalid argument". What is this and how can this solved? Robert ============== ...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.