473,386 Members | 1,736 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,386 software developers and data experts.

Run If all records selected have same value in a field... Problem?

112 100+
I am running Access 2007.
I have a button on a pop-up box, when clicked it runs a report on selected records based on whether a check box is selected. If no records are selected then it only prints a report for the current record you are on. It selects the report to print based on what is in a combo box on my main form. However if you select three records that have a different value in that combo box, it will print them all based on the first records value. So I get one report that is right and two that are wrong. I would like to have it not run if the records selected have different values in the combo box and give me a message “Can Not Print. Check to make sure you are running the same report!” I not sure how to do this? See code below

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command10_Click()
  2.  
  3.  
  4. 'Declare stuff we need
  5.     Dim DB As Database
  6.     Dim Ptogset As Recordset
  7.  
  8.  
  9.     'Setting the stuff
  10.     Set DB = CurrentDb()
  11.     Set Ptogset = DB.OpenRecordset("SELECT Search FROM Description")
  12.  
  13.  
  14.     'Set the searcher counter
  15.     Dim Searcher As Integer
  16.         Searcher = 0
  17.  
  18.     'Search trought the recordset for any records that fits the condition
  19.     Do Until Ptogset.EOF
  20.         Searcher = Ptogset.Fields("Search").Value + Searcher
  21.         Ptogset.MoveNext
  22.     Loop
  23.  
  24.     'If there's no records with the match criteria, build simple condition
  25.     Dim Condition As String
  26.  
  27.     If Searcher = 0 Then
  28.         Condition = "[Accession Number]=Forms!frmDescription!txtAccNum"
  29.     Else
  30.         Condition = "[Search]=true"
  31.     End If
  32.  
  33.    Dim printLocate As String
  34.     printLocate = Forms!frmDescription!Combo6586
  35.  
  36.         Select Case printLocate
  37.         Case "Photo File 4x5": DoCmd.OpenReport "rpt4x5", acViewPreview, , Condition
  38.         Case "Photo File 5x7": DoCmd.OpenReport "rpt5X7", acViewPreview, , Condition
  39.         Case "Photo File 8x10": DoCmd.OpenReport "rpt8x10", acViewPreview, , Condition
  40.         Case "Photo File 9x12": DoCmd.OpenReport "rpt9x12", acViewPreview, , Condition
  41.         Case "Photo File 9x14": DoCmd.OpenReport "rpt9x14", acViewPreview, , Condition
  42.         Case "Photo File 11x15": DoCmd.OpenReport "rpt11x15", acViewPreview, , Condition
  43.         Case "Archive File 4x5": DoCmd.OpenReport "rptA4x5", acViewPreview, , Condition
  44.         Case "Archive File 5x7": DoCmd.OpenReport "rptA5X7", acViewPreview, , Condition
  45.         Case "Archive File 8x10": DoCmd.OpenReport "rptA8x10", acViewPreview, , Condition
  46.         Case "Archive File 9x12": DoCmd.OpenReport "rptA9x12", acViewPreview, , Condition
  47.         Case "Archive File 9x14": DoCmd.OpenReport "rptA9x14", acViewPreview, , Condition
  48.         Case "Archive File 11x15": DoCmd.OpenReport "rptA11x15", acViewPreview, , Condition
  49.         Case "Stereograph Card File": DoCmd.OpenReport "rpt5X7", acViewPreview, , Condition
  50.  
  51.         Case Else:
  52.             MsgBox "Cannot produce report for this artifact. Look in the permanent location."
  53.  
  54.  
  55.     End Select
  56.  
  57. DoCmd.Close acForm, "frmPrintControlBox"
  58.  
  59. End Sub

Any help would be great!
Thanks
Apr 4 '11 #1
6 2292
NeoPa
32,556 Expert Mod 16PB
Redbeard:
It selects the report to print based on what is in a combo box on my main form. However if you select three records that have a different value in that combo box, it will print them all based on the first records value.
WTF does that mean? However many times I read that I cannot understand how records have values in the combobox. The only combobox referred to so far selects a report to run. What are you trying to say here?
Apr 4 '11 #2
Redbeard
112 100+
I am sorry that I have not explained my problem well. It is hard sometime to explain what you are doing when you are so involved in it, I will try to clarify.
The database is set up to track photographs… so each record is of one photograph. The combo box has values from my main table which are the locations that the photos are stored it. So there are 13 different locations that the photos can be stored based on size. The reports are actually set to the size of envelops that the photos will be stored in. So when I click the button it looks at the combo box that has the location of the photo and selects the report to run based on that. For example if I select a record with the location of “Photo File 4x5” it prints on an envelope that holds a 4x5 photo (prints the name of photo and thumbnail photo on envelop). I have set the reports up to run based on the storage location. The problem is when I print the envelops, I do them 100 at a time. So if I select 100 records and 90 of the have the 4x5 location and 10 of them have a 5x7 location it will run whatever report size based on the first records location. So I would either get 100 4x5 envelops printed, 10 of which should have been on 5x7 envelops. Or 100 5x7 envelopes, which 90 of should have been on 4x5’s. I basically need something to stop me from printing if the location field does not match on all record selected for print. I am basically trying to idiot proof the operation.
I hope I have been clearer with this explanation. I think before it sounded like the combo box I was using was not connected to my records and had a list of values that were just linked to the report names. So I you selected “Photo File 4x5” it just ran that report for the records selected. I had not considered doing it that way, but I guess I could if the method about is too complex.
Apr 5 '11 #3
NeoPa
32,556 Expert Mod 16PB
Sorry for the delay in posting. I must admit I was putting off trying to determine what you were saying as it looked indecipherable. It makes some sort of sense though (reading through it carefully) and I think I understand what you're after. The solution will be hard to explain though, as the code is as it stands is somewhat unorthodox and doesn't lend itself well to anything very flexible (which we will need to incorporate the solution I'm about to propose).

The basic concept is that the code determine the report that has been selected (It will be required in a string variable so the Select ... Case construct will need to be changed to handle this), it then gets the .RecordSource property of this report and opens a recordset using this data (See Subqueries in SQL for explanation of this idea.) - not forgetting to apply the filter already determined.

Assuming your .RecordSource value is "SELECT * FROM [Description]" (QueryDef names work just as well. This simply illustrates it can even handle a SQL string.) and your Condition variable is set to "[Accession Number]=31" we would need something like the following as a recordset to be opened and checked :
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM (SELECT * FROM [Description])
  3. WHERE ([Accession Number]=31)
You already have recordset processing in your code so you don't need me to tell you (as I have no information as to what you are checking in the dataset anyway) how to check through these records to ensure all match the requirements you have that we still don't know much about. Clearly, this code will enable you to throw an exception message or not depending on whether or not it finds an exception in the recordset.


All that said, a more sensible approach (fundamentally easier and probably a more logical place for the checking to be anyway) would be to add some (very similar) code to each of the reporst such that they test their own data as (or before) they run and either skip any offending records or throw an error message instead and abort.

These are my ideas on the issue. Let me know if you're still interested and/or whether you need any of them padded out somewhat.
May 31 '11 #4
Redbeard
112 100+
Thanks for the response Neopa. I abandon my idea awhile ago after not being able to figure it out. However I did figure out another way to do it. I created a pop-up with a combo box that has a drop down with all the envelop sizes that I can print. When I select the size I want, it runs a query that looks for the ones I have selected and the size I picked. If there are none I get a pop up message that tells me there are no records selected. If there are some it will print them and if I have selected other of a different size it will not print those... which was the point of this to start with. So I got it to work just not the way I wanted it. Again, thanks for the help, I always appreciate it.
May 31 '11 #5
Rabbit
12,516 Expert Mod 8TB
What you needed to do was to build in the size criteria into the report's record source. Then, you can do a count using each size and open up the report if there is at least one record.
May 31 '11 #6
NeoPa
32,556 Expert Mod 16PB
It sounds like your solution is a pretty appropriate one in the end anyway, and every solution you find adds to your experience. Well done.
May 31 '11 #7

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

Similar topics

5
by: Elvis V. | last post by:
Good morning, I have a table with three fields, Buildings, Floors and Rooms. This is what I would like to do; in my form when I select Building1 in my drop down box for Buildings, when I go to the...
4
by: Tom Keane | last post by:
Okay, woo, yet another issue I have. I remember writing about this issue AGES ago, but I don't think it worked, or I just left it for too long. I have a query that searches for specific records...
15
by: shaqattack1992-newsgroups | last post by:
Hello Everyone, Let me explain my problem. I have included 2 dashes between each pair of records to make it easier to see what goes together. In reality, it is just a long list of results...
1
by: Sam | last post by:
Hi, I don't know how to specify the display and value field for a combobox when using AddRange to fill the combo. Here is what I have so far: -A function to build an array of object : Dim...
3
by: brian.a.kennedy | last post by:
I am a rookie and am looking to create records based on a field value. For example - I currently have sales data for three employees: Employee 1 has sold 12 units, EE 2 has 8 and EE 3 has 10....I...
2
mickyp
by: mickyp | last post by:
Hi There, I have an access database where I would like to set two fields to the same value. Both fields are in the same table called Sampletbl The one field is called Year and the other Years....
1
by: ahmurad | last post by:
Dear all, I am new group user, computer science graduate; just have joined this established group and thanks to all. I am working in network field but so much interested in web (PHP) field. Recently...
2
by: JC2710 | last post by:
Hi I would like a Query that Updates a field to indicate that records have a duplicate entry( records with same values). My table is ..... Code........Process..........Quantity ...
1
by: scottbouley | last post by:
I'm building a view in SQL Server 2000 Enterprize Manager to find any parent supply request records that are "Open" where all of the child detail records are "Completed". The two tables are related...
15
by: amy1 | last post by:
Hello everyone, I'm new here and new to Access2007 as well! I have a multi-value field in a form, and would like to calculate the total of the selected values in this field and place the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
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$) { } ...
0
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...
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
1
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...
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
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...

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.