472,811 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 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 5609
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.