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 ... -
If (Qty < SolderieQty Or Qty = SolderieQty) Then
-
If (Qty < sumq) Then
-
MsgBox "check the Quantity. qty < sumq"
-
Me.q1.SetFocus
-
End If
-
If (Qty > sumq) Then
-
MsgBox "check the Quantity. qty > sumq"
-
Me.q1.SetFocus
-
End If
-
-
If (Qty = sumq) Then
-
'ADD the record into SendDetails table
-
If ((Not IsNull(Article)) And (Not IsNull(sentdate)) And (Not IsNull(SendFrom)) And (Not IsNull(SendTo))) Then
-
MsgBox "first"
-
If (CheckIfSent(CLng(Forms![Transfer]!Article), CDate(Forms![Transfer]!send_Date), CStr(Forms![Transfer]!SendFrom), CStr(Forms![Transfer]!SendTo))) Then
-
MsgBox "you have sent this article before to the same location"
-
Forms![Transfer]![Article].SetFocus
-
MsgBox "aaaa"
-
Else
-
If (CheckIfSent(CLng(Forms![Transfer]!Article), CDate(Forms![Transfer]!send_Date), CStr(Forms![Transfer]!SendFrom), CStr(Forms![Transfer]!SendTo)) = False) Then
-
MsgBox "bbbb"
-
InsertIntoSendDetails CDate(sentdate), CStr(SendFrom), CStr(SendTo), CLng(Article), CLng(Qty), CLng(q1), CLng(q2), _
-
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)
-
-
Me.st_q1.Value = (Nz(Me.st_q1.Value, 0) - Nz(Me.q1.Value, 0))
-
Me.st_relax_q1.Value = (Nz(Me.st_relax_q1.Value, 0) + Nz(Me.q1.Value, 0))
-
Me.st_q2.Value = (Nz(Me.st_q2.Value, 0) - Nz(Me.q2.Value, 0))
-
Me.st_relax_q2.Value = (Nz(Me.st_relax_q2.Value, 0) + Nz(Me.q2.Value, 0))
-
Me.st_q3.Value = (Nz(Me.st_q3.Value, 0) - Nz(Me.q3.Value, 0))
-
Me.st_relax_q3.Value = (Nz(Me.st_relax_q3.Value, 0) + Nz(Me.q3.Value, 0))
-
Me.st_q4.Value = (Nz(Me.st_q4.Value, 0) - Nz(Me.q4.Value, 0))
-
Me.st_relax_q4.Value = (Nz(Me.st_relax_q4.Value, 0) + Nz(Me.q4.Value, 0))
-
Me.st_q5.Value = (Nz(Me.st_q5.Value, 0) - Nz(Me.q5.Value, 0))
-
Me.st_relax_q5.Value = (Nz(Me.st_relax_q5.Value, 0) + Nz(Me.q5.Value, 0))
-
Me.st_q6.Value = (Nz(Me.st_q6.Value, 0) - Nz(Me.q6.Value, 0))
-
Me.st_relax_q6.Value = (Nz(Me.st_relax_q6.Value, 0) + Nz(Me.q6.Value, 0))
-
Me.st_q7.Value = (Nz(Me.st_q7.Value, 0) - Nz(Me.q7.Value, 0))
-
Me.st_relax_q7.Value = (Nz(Me.st_relax_q7.Value, 0) + Nz(Me.q7.Value, 0))
-
Me.st_q8.Value = (Nz(Me.st_q8.Value, 0) - Nz(Me.q8.Value, 0))
-
Me.st_relax_q8.Value = (Nz(Me.st_relax_q8.Value, 0) + Nz(Me.q8.Value, 0))
-
Me.st_q9.Value = (Nz(Me.st_q9.Value, 0) - Nz(Me.q9.Value, 0))
-
Me.st_relax_q9.Value = (Nz(Me.st_relax_q9.Value, 0) + Nz(Me.q9.Value, 0))
-
Me.st_q10.Value = (Nz(Me.st_q10.Value, 0) - Nz(Me.q10.Value, 0))
-
Me.st_relax_q10.Value = (Nz(Me.st_relax_q10.Value, 0) + Nz(Me.q10.Value, 0))
-
Me.st_q11.Value = (Nz(Me.st_q11.Value, 0) - Nz(Me.q11.Value, 0))
-
Me.st_relax_q11.Value = (Nz(Me.st_relax_q11.Value, 0) + Nz(Me.q11.Value, 0))
-
Me.st_q12.Value = (Nz(Me.st_q12.Value, 0) - Nz(Me.q12.Value, 0))
-
Me.st_relax_q12.Value = (Nz(Me.st_relax_q12.Value, 0) + Nz(Me.q12.Value, 0))
-
Me.st_q13.Value = (Nz(Me.st_q13.Value, 0) - Nz(Me.q13.Value, 0))
-
Me.st_relax_q13.Value = (Nz(Me.st_relax_q13.Value, 0) + Nz(Me.q13.Value, 0))
-
Me.st_q14.Value = (Nz(Me.st_q14.Value, 0) - Nz(Me.q14.Value, 0))
-
Me.st_relax_q14.Value = (Nz(Me.st_relax_q14.Value, 0) + Nz(Me.q14.Value, 0))
-
Me.SolderieStock.Value = (Nz(Me.SolderieStock.Value, 0) - Me.Qty.Value)
-
Me.RelaxStock.Value = (Nz(Me.RelaxStock.Value, 0) + Me.Qty.Value)
-
End If
-
End If
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
-
Else
-
MsgBox "Qty entered more than the solderie stock quantity"
-
Me.Qty.SetFocus
-
End If
-
4 2477
The problem is at line#19 and line#20. Your code should look like this ... - If (Qty < SolderieQty Or Qty = SolderieQty) Then
-
If (Qty < sumq) Then
-
MsgBox "check the Quantity. qty < sumq"
-
Me.q1.SetFocus
-
End If
-
-
If (Qty > sumq) Then
-
MsgBox "check the Quantity. qty > sumq"
-
Me.q1.SetFocus
-
End If
-
-
If (Qty = sumq) Then
-
'ADD the record into SendDetails table
-
If ((Not IsNull(Article)) And (Not IsNull(sentdate)) And (Not IsNull(SendFrom)) And (Not IsNull(SendTo))) Then
-
MsgBox "first"
-
If (CheckIfSent(CLng(Forms![Transfer]!Article), CDate(Forms![Transfer]!send_Date), CStr(Forms![Transfer]!SendFrom), CStr(Forms![Transfer]!SendTo))) Then
-
MsgBox "you have sent this article before to the same location"
-
Forms![Transfer]![Article].SetFocus
-
MsgBox "aaaa"
-
ElseIf (CheckIfSent(CLng(Forms![Transfer]!Article), CDate(Forms![Transfer]!send_Date), CStr(Forms![Transfer]!SendFrom), CStr(Forms![Transfer]!SendTo)) = False) Then
-
MsgBox "bbbb"
-
InsertIntoSendDetails CDate(sentdate), CStr(SendFrom), CStr(SendTo), CLng(Article), CLng(Qty), CLng(q1), CLng(q2), _
-
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)
-
-
Me.st_q1.Value = (Nz(Me.st_q1.Value, 0) - Nz(Me.q1.Value, 0))
-
Me.st_relax_q1.Value = (Nz(Me.st_relax_q1.Value, 0) + Nz(Me.q1.Value, 0))
-
Me.st_q2.Value = (Nz(Me.st_q2.Value, 0) - Nz(Me.q2.Value, 0))
-
Me.st_relax_q2.Value = (Nz(Me.st_relax_q2.Value, 0) + Nz(Me.q2.Value, 0))
-
Me.st_q3.Value = (Nz(Me.st_q3.Value, 0) - Nz(Me.q3.Value, 0))
-
Me.st_relax_q3.Value = (Nz(Me.st_relax_q3.Value, 0) + Nz(Me.q3.Value, 0))
-
Me.st_q4.Value = (Nz(Me.st_q4.Value, 0) - Nz(Me.q4.Value, 0))
-
Me.st_relax_q4.Value = (Nz(Me.st_relax_q4.Value, 0) + Nz(Me.q4.Value, 0))
-
Me.st_q5.Value = (Nz(Me.st_q5.Value, 0) - Nz(Me.q5.Value, 0))
-
Me.st_relax_q5.Value = (Nz(Me.st_relax_q5.Value, 0) + Nz(Me.q5.Value, 0))
-
Me.st_q6.Value = (Nz(Me.st_q6.Value, 0) - Nz(Me.q6.Value, 0))
-
Me.st_relax_q6.Value = (Nz(Me.st_relax_q6.Value, 0) + Nz(Me.q6.Value, 0))
-
Me.st_q7.Value = (Nz(Me.st_q7.Value, 0) - Nz(Me.q7.Value, 0))
-
Me.st_relax_q7.Value = (Nz(Me.st_relax_q7.Value, 0) + Nz(Me.q7.Value, 0))
-
Me.st_q8.Value = (Nz(Me.st_q8.Value, 0) - Nz(Me.q8.Value, 0))
-
Me.st_relax_q8.Value = (Nz(Me.st_relax_q8.Value, 0) + Nz(Me.q8.Value, 0))
-
Me.st_q9.Value = (Nz(Me.st_q9.Value, 0) - Nz(Me.q9.Value, 0))
-
Me.st_relax_q9.Value = (Nz(Me.st_relax_q9.Value, 0) + Nz(Me.q9.Value, 0))
-
Me.st_q10.Value = (Nz(Me.st_q10.Value, 0) - Nz(Me.q10.Value, 0))
-
Me.st_relax_q10.Value = (Nz(Me.st_relax_q10.Value, 0) + Nz(Me.q10.Value, 0))
-
Me.st_q11.Value = (Nz(Me.st_q11.Value, 0) - Nz(Me.q11.Value, 0))
-
Me.st_relax_q11.Value = (Nz(Me.st_relax_q11.Value, 0) + Nz(Me.q11.Value, 0))
-
Me.st_q12.Value = (Nz(Me.st_q12.Value, 0) - Nz(Me.q12.Value, 0))
-
Me.st_relax_q12.Value = (Nz(Me.st_relax_q12.Value, 0) + Nz(Me.q12.Value, 0))
-
Me.st_q13.Value = (Nz(Me.st_q13.Value, 0) - Nz(Me.q13.Value, 0))
-
Me.st_relax_q13.Value = (Nz(Me.st_relax_q13.Value, 0) + Nz(Me.q13.Value, 0))
-
Me.st_q14.Value = (Nz(Me.st_q14.Value, 0) - Nz(Me.q14.Value, 0))
-
Me.st_relax_q14.Value = (Nz(Me.st_relax_q14.Value, 0) + Nz(Me.q14.Value, 0))
-
Me.SolderieStock.Value = (Nz(Me.SolderieStock.Value, 0) - Me.Qty.Value)
-
Me.RelaxStock.Value = (Nz(Me.RelaxStock.Value, 0) + Me.Qty.Value)
-
End If
-
End If
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
-
Else
-
MsgBox "Qty entered more than the solderie stock quantity"
-
Me.Qty.SetFocus
-
End If
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:
And then replace lines 25 through 52 with this: -
For xLoop = 1 to 14
-
Me.Controls("st_q" & xLoop).Value = (Nz(Me.Controls("st_q" & xLoop).Value, 0) - Nz(Me.Controls("q" & xLoop).Value, 0))
-
-
Me.Controls("st_relax_q" & xLoop).Value = (Nz(Me.Controls("st_relax_q" & xLoop).Value, 0) + Nz(Me.Controls("q" & xLoop).Value, 0))
-
Next
-
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.
Here is another Version of dsatino's explanation in Post# 3, which you may/may not find easier to understand and implement: - Dim bytCtrlCtr As Integer
-
Dim ctl1 As Control
-
Dim ctl2 As Control
-
Dim ctl3 As Control
-
-
For bytCtrlCtr = 1 To 14
-
Set ctl1 = Me.Controls("st_q" & CStr(bytCtrlCtr))
-
Set ctl2 = Me.Controls("q" & CStr(bytCtrlCtr))
-
Set ctl3 = Me.Controls("st_relax_q" & CStr(bytCtrlCtr))
-
-
ctl1 = (Nz(ctl1, 0) - Nz(ctl2, 0))
-
ctl3 = (Nz(ctl3, 0) + Nz(ctl2, 0))
-
Next
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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.
...
|
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).
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
==============
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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...
|
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: 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,...
| |