How can i make my Else..If statement make look no so
cumbersome? Besides the condition for previewing the report
doesnt work,may be my If condition does no apply properly.
Perhaps this is due to the many conditions in my If else statements.
Do i have a mistake in my function CmdStockReceipt ?
Private Sub CmdStockReceipt _Click()
Dim f As Form
Set f = Forms![FOrderInformati on]
If IsNull(f![LstStockReceipt]) Then
DoCmd.Beep
MsgBox " Please select Order first ! "
Exit Sub
Else
Dim stLinkCriteria As String
Dim stDocName As String
stDocName = "Invoice"
stLinkCriteria = "orderid = " & f![LstStockReceipt]
Dim intPrint As Integer
Dim intAnswer As Integer
intAnswer = MsgBox(" Delete? ", vbQuestion + vbYesNo)
If intAnswer = vbYes Then
Application.Ech o False
CancelOrderOnOf fice
Else
intPrint = MsgBox(" Print? ", vbQuestion + vbYesNo)
If intPrint = vbYes Then
FncPrint
Else
DoCmd.OpenRepor t stDocName, acPreview, , stLinkCriteria
VisibleOrder
Reports![invoice]![LblStockreceipt].Visible = True
End If
End If
End If
End Sub
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it! 2 5654
Peter yeshew <fr*******@abv. bg> wrote in
news:3f******** *************** @news.frii.net: How can i make my Else..If statement make look no so cumbersome? Besides the condition for previewing the report doesnt work,may be my If condition does no apply properly. Perhaps this is due to the many conditions in my If else statements. Do i have a mistake in my function CmdStockReceipt ?
You can do some simplification, see my comments in the code.
Private Sub CmdStockReceipt _Click() Dim f As Form Set f = Forms![FOrderInformati on] If IsNull(f![LstStockReceipt]) Then
If CmdStockReceipt is a control on [FOrderInformati on], you are
better off using the me! reference. Yhen you dont need to dim and
set variable f.
DoCmd.Beep MsgBox " Please select Order first ! " Exit Sub
Since you Exit sub here, you don't need the else, remove it and
relocate the corresponding End if.
Else Dim stLinkCriteria As String Dim stDocName As String stDocName = "Invoice" stLinkCriteria = "orderid = " & f![LstStockReceipt] Dim intPrint As Integer Dim intAnswer As Integer intAnswer = MsgBox(" Delete? ", vbQuestion + vbYesNo) If intAnswer = vbYes Then
You can combine the three statements into one:
If Msgbox("Delete? ", vbquestion+vbye sno) = vbyes then Application.Ech o False CancelOrderOnOf fice Else intPrint = MsgBox(" Print? ", vbQuestion + vbYesNo) If intPrint = vbYes Then
And again
ElseIf MsgBox(" Print? ", vbQuestion + vbYesNo) = VbYes then
Note the ElseIf piggybacks on tHe existing If, and does not require
a separate End if
FncPrint Else DoCmd.OpenRepor t stDocName, acPreview, , stLinkCriteria VisibleOrder
'Is VisibleOrder a cut and paste error, or a subprocedure?
Reports![invoice]![LblStockreceipt].Visible = True End If End If End If End Sub
Redone gives me:
Private Sub CmdStockReceipt _Click()
If IsNull(me![LstStockReceipt]) Then
DoCmd.Beep
MsgBox " Please select Order first ! "
Exit Sub
End If
Dim stLinkCriteria As String
Dim stDocName As String
stDocName = "Invoice"
stLinkCriteria = "orderid = " & f![LstStockReceipt]
If Msgbox("Delete? ", vbquestion+vbye sno) = vbyes then
Application.Ech o False
CancelOrderOnOf fice
ElseIf MsgBox(" Print? ", vbQuestion + vbYesNo) = VbYes then
FncPrint
Else
DoCmd.OpenRepor t stDocName, acPreview,,stLi nkCriteria
Reports![invoice]![LblStockreceipt].Visible = True
End If
End Sub
Bob Q
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Steve Jorgensen <no****@nospam. nospam> wrote in
news:pr******** *************** *********@4ax.c om: For the sake of legibility, when I'm comparing a constant to the return value of a long function call, I generally put the constant first, so it's easier for the eye to find.
Thanks for the tip. I've just gotten used to the rule that puts the
constant on the RightHand side of an equation.
Then again, I tend to prefer a Select Case block if I'm dealing with more than one return value as in this case which really makes the constant compare easy to read. To me, putting another message box call in the elseif may make the code more compact, but actually makes it more confusing to read.
It is not an issue here, but a select case where there can be ONLY
TWO results imposes a performance hit over If-Else. Inside a loop
where it gets called thousands of times, it makes a difference, so
I got into the habit of using each construct where applicable.
Bob Finally, the If for the first Msgbox actually looks like another guard clause to me.
I'd use a custom form with the Print, Delete, do nothing on one
form.
Bob If vbYes = Msgbox("Delete? ", vbquestion+vbye sno) Then Application.Ech o False CancelOrderOnOf fice Exit Sub End If Select Case MsgBox(" Print? ", vbQuestion + vbYesNo) Case VbYes FncPrint Case Else DoCmd.OpenRepor t stDocName, acPreview,,stLi nkCriteria Reports![invoice]![LblStockreceipt].Visible = True End Select This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kendal Goodrich |
last post by:
In the setup project I am trying to create, I am wanting to search to see if
DirectX 8 is installed on the local machine. I figured the best way to
determine would be a registry key search, so I add one. The problem comes
in with the properties for the registry key search. The properties are
RegKey and Value. In viewing the registry editor, the registry key is
Software\Microsoft\DirectX. Within that, you have a value name and a value...
|
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 :SOFTWARE\Add1\Add2
Root : vsdrrHKLM
Value : Deux
|
by: Ben R. |
last post by:
In an article I was reading
(http://www.ftponline.com/vsm/2005_06/magazine/columns/desktopdeveloper/),
I read the following:
"The ending condition of a VB.NET for loop is evaluated only once, while the
C# for loop ending condition is evaluated on every iteration."
Is this accurate? I don't understand how you could get away without
evaluating the ending condition at every iteration. Otherwise, how would you
|
by: Yohan |
last post by:
Hello,
I have a question concerning the template classes and their parameters.
Is it possible to set a condition on the template parameters in a way
that could block the compilation if the condition isn't true?
(e.g. by throwing an error message to the compiler).
And is it possible to use this type of condition to make the compiler
choose the best method (between some others).
Here is an example to illustrate my question:
|
by: das |
last post by:
hello all,
this might be simple:
I populate a temp table based on a condition from another table:
select @condition = condition from table1 where id=1
in my stored procedure I want to do this:
if @condition = 0
| |
by: joh12005 |
last post by:
Hello,
i posted for suggestions a little idea even if it still needs further
thoughts but as i'm sure you could help :)
if would like to implement some kind of Condition class which i coud
use to build bricks of more complex condition, conditions are based on
fields by using regexp
class Condition:
|
by: Claudio Grondi |
last post by:
Sometimes it is known in advance, that the time spent in a loop will be
in order of minutes or even hours, so it makes sense to optimize each
element in the loop to make it run faster.
One of instructions which can sure be optimized away is the check for
the break condition, at least within the time where it is known that the
loop will not reach it.
Any idea how to write such a loop?
e.g.
|
by: Jane T |
last post by:
I appreciate how difficult it is to resolve a problem without all the
information but maybe someone has come across a similar problem.
I have an 'extract' table which has 1853 rows when I ask for all rows where
period_ = 3. The allocation table for info has 210 rows.
I have two scripts below. The first script where I specify a period on a
join, brings back 1853 lines and works. The second script where I specify
the period in the...
|
by: RN1 |
last post by:
I have a DataGrid with an EditCommandColumn. In the EditCommand sub of
the DataGrid, there is an If condition. This If condition is True for
some rows in the DataGrid whereas it is False for the other rows in
the DataGrid. I want that only those rows whose If condition evaluates
to True should go into the editable mode when the Edit link in the
EditCommandColumn is clicked where as the rows whose If condition
evaluates to False shouldn't...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |