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

performing an operation via a button from different list

106 100+
I have few list boxes. and I have few buttons which should do the same operation for any of the selected items from any list box.

For example I have a view button which open a report for any selection from a list.

behind the view button I have this code
Expand|Select|Wrap|Line Numbers
  1.  
  2. If (Len([List1]) > 0) Then
  3.         DoCmd.OpenReport stDocName1, acPreview
  4.     ElseIf (Len([List2]) > 0) Then
  5.         DoCmd.OpenReport stDocName2, acPreview
  6.     ElseIf (Len([List3]) > 0) Then
  7.         DoCmd.OpenReport stDocName3, acPreview
  8.     ElseIf (Len([List4]) > 0) Then
  9.         DoCmd.OpenReport stDocName4, acPreview
  10.     Else
  11.         MsgBox "Please select an item from any of the lists provided then press the button", vbCritical, "Warning"
  12.     End If
  13.  
the problem is that it only let me view the report for the first selection,
for example I select an item from list1, it works fine and I see the reports, but when i go and select an item from list2 two, it still shows me the same report from the first selection.

Any ideas why?

Regards,
Nov 2 '06 #1
5 1401
pks00
280 Expert 100+
I have few list boxes. and I have few buttons which should do the same operation for any of the selected items from any list box.

For example I have a view button which open a report for any selection from a list.

behind the view button I have this code
Expand|Select|Wrap|Line Numbers
  1.  
  2. If (Len([List1]) > 0) Then
  3.         DoCmd.OpenReport stDocName1, acPreview
  4.     ElseIf (Len([List2]) > 0) Then
  5.         DoCmd.OpenReport stDocName2, acPreview
  6.     ElseIf (Len([List3]) > 0) Then
  7.         DoCmd.OpenReport stDocName3, acPreview
  8.     ElseIf (Len([List4]) > 0) Then
  9.         DoCmd.OpenReport stDocName4, acPreview
  10.     Else
  11.         MsgBox "Please select an item from any of the lists provided then press the button", vbCritical, "Warning"
  12.     End If
  13.  
the problem is that it only let me view the report for the first selection,
for example I select an item from list1, it works fine and I see the reports, but when i go and select an item from list2 two, it still shows me the same report from the first selection.

Any ideas why?

Regards,

Most probably due to your ElseIf's?

Why dont u just do if statements without doing any else in

Expand|Select|Wrap|Line Numbers
  1.     Dim bReportDone as Boolean
  2.  
  3.     bReportDone = False
  4.  
  5.     If (Len([List1]) > 0) Then
  6.         DoCmd.OpenReport stDocName1, acPreview
  7.         bReportDone = True
  8.     End if
  9.  
  10.     If (Len([List2]) > 0) Then
  11.         DoCmd.OpenReport stDocName2, acPreview
  12.         bReportDone = True
  13.     End if
  14.  
  15.     If (Len([List3]) > 0) Then
  16.         DoCmd.OpenReport stDocName3, acPreview
  17.         bReportDone = True
  18.     End if
  19.  
  20.     If (Len([List4]) > 0) Then
  21.         DoCmd.OpenReport stDocName4, acPreview
  22.         bReportDone = True
  23.     End if
  24.  
  25.     If bReportDone = False Then
  26.         MsgBox "Please select an item from any of the lists provided then press the button", vbCritical, "Warning"
  27.     End If
  28.  
  29.  
Nov 2 '06 #2
NeoPa
32,556 Expert Mod 16PB
Tara,

pks00's answer will enable you to run multiple reports (for all lists that have anything selected).
If you only want to run the report for the list just selected then you will need to deselect any other lists first.

BTW To use the Select Case statement where the options are based on different variables, you can use code like this :-
Expand|Select|Wrap|Line Numbers
  1. Select Case TRUE
  2.     Case Len(List1)>0
  3.         {code}
  4.     Case Len(List2)>0
  5.         {code}
  6. End Select
Select Case is generally recommended over any complicated If structure as it's more manageable and (generally considered) more readable.

Have fun.
Nov 2 '06 #3
tara99
106 100+
Tara,

pks00's answer will enable you to run multiple reports (for all lists that have anything selected).
If you only want to run the report for the list just selected then you will need to deselect any other lists first.

BTW To use the Select Case statement where the options are based on different variables, you can use code like this :-
Expand|Select|Wrap|Line Numbers
  1. Select Case TRUE
  2.     Case Len(List1)>0
  3.         {code}
  4.     Case Len(List2)>0
  5.         {code}
  6. End Select
Select Case is generally recommended over any complicated If structure as it's more manageable and (generally considered) more readable.

Have fun.

Hi Neopa

Can you please explain more what do I have to do/
tnx
Nov 3 '06 #4
pks00
280 Expert 100+
Have I got my understanding wrong

Do u want to run all the selected reports or just one from any selected item in any list?

I thought it was the former
Nov 3 '06 #5
NeoPa
32,556 Expert Mod 16PB
Hi Neopa

Can you please explain more what do I have to do/
tnx
I will try to answer specific questions but I'm not inclined to do the whole job for you.
If you can explain clearly what it is you need to know or understand I will help if I can.
Nov 3 '06 #6

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

Similar topics

12
by: Brett L. Moore | last post by:
Hi, I have had trouble determining whether the STL list.size() operation is O(1) or O(n). I know the list is a doubly-linked list, so if the size() operation begins at the head, then counts to...
0
by: Sundown | last post by:
I am trying to create a custom button control for the web that, when clicked, disables and changes the text of itself and a bunch of other controls (in the collection). My goal is to end up with a...
2
by: compupix | last post by:
I hope I'm in the right group for this. I'm using Google's Picasa program to create formatted webpages of my images. Picasa acts on html and tpl files as it creates the final html pages. I...
0
by: yariv | last post by:
Hello All, I am having a very strange problem. while trying to access http page on the web. I happen to have some problems at specific machines. the exception I get is: *************...
8
by: John | last post by:
Here is the current error that im getting when building my solution. The only thing i can think of is that i needed to install visual studio 6 after visual studio .net was already installed to...
1
by: RJN | last post by:
Hi I have 2 operations to perform one is to upload data and the second is to generate report. Both take huge time(more than 20 mins and I believe by that time session would have expired) and...
0
by: Mossman | last post by:
Hello, I posted this problem in another thread and received no response. I need some input at what to look at next. So, if anyone out there as any suggestions, please respond to this message....
0
by: Abuzar755 | last post by:
Hello, I have problem with Postgre Sql. I am beginner in Delphi and also in DataBase. I want to connect to Postgre Sql via Delphi,I use AdoConnection, DataSource, AdoTable and DBGrid.OnCreate...
3
by: ellishnoo | last post by:
Hi there, Please be kind, I have seen some posts where you tell people off for asking without investigating, Im sure most have, anyway I have. Ive only been doin VB 2008 for 7 weeks, and have...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
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...
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...

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.