473,402 Members | 2,061 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,402 software developers and data experts.

muddled if condition


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![FOrderInformation]
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.Echo False
CancelOrderOnOffice
Else
intPrint = MsgBox(" Print? ", vbQuestion + vbYesNo)
If intPrint = vbYes Then
FncPrint
Else
DoCmd.OpenReport 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!
Nov 12 '05 #1
2 5641
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![FOrderInformation]
If IsNull(f![LstStockReceipt]) Then
If CmdStockReceipt is a control on [FOrderInformation], 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+vbyesno) = vbyes then Application.Echo False
CancelOrderOnOffice
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.OpenReport 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+vbyesno) = vbyes then
Application.Echo False
CancelOrderOnOffice
ElseIf MsgBox(" Print? ", vbQuestion + vbYesNo) = VbYes then
FncPrint
Else
DoCmd.OpenReport stDocName, acPreview,,stLinkCriteria
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!


Nov 12 '05 #2
Steve Jorgensen <no****@nospam.nospam> wrote in
news:pr********************************@4ax.com:
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+vbyesno) Then
Application.Echo False
CancelOrderOnOffice
Exit Sub
End If
Select Case MsgBox(" Print? ", vbQuestion + vbYesNo)
Case VbYes
FncPrint
Case Else
DoCmd.OpenReport stDocName, acPreview,,stLinkCriteria
Reports![invoice]![LblStockreceipt].Visible = True
End Select

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
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...
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...
3
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,...
3
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...
5
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...
4
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...
16
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...
4
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...
0
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...
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...
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
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.