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

How to display records that don't match between two recordsets

EDIT: Solution below, read on! (Spoiler alert: I used DCount.)

As stated in the title I have two recordsets and am comparing multiple values from one to the other. My code works fine for the perfect matches but the excel sheet I'm importing isn't always complete so I will need to know what records to update manually.

Though I wrote this code I am new to Access and to VBA so I have no clue how to effectively retrieve or even display the information I need. (I was thinking about displaying with a Report type recordset?)

IPAC is basically a spreadsheet we get with the cost of jobs. They don't have a Unique Identifier so I compared several fields. In case you are wondering why I didn't use a "With" statement that's because it's already pretty confusing to me without nested "withs" haha. I hope that is enough relevant detail, I really appreciate any help you can give. Even if you can't solve the problem I welcome any input about my practices.

Thanks!

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdImortIPAC_Click()
  2.  
  3.     Dim intResponse As Integer
  4.  
  5.     intResponse = msgbox("Do you wish to import the IPAC from" & vbLf & _
  6.     "C:\TransferSpreadsheet\IPAC.xls?" & vbLf & vbLf & vbLf & _
  7.     "This action will change mulitple jobs." & vbLf & _
  8.     "It cannot easily be undone!", vbYesNo, "Are you sure?")
  9.     If intResponse = vbYes Then
  10.  
  11. '   The spreadsheeet has to have this exact name and location
  12.     DoCmd.TransferSpreadsheet acImport, , "tblIPAC", _
  13.           "C:\TransferSpreadsheet\IPAC.xls", True
  14.  
  15.     Dim dbJMM As DAO.Database
  16.     Dim rsIPAC As DAO.Recordset
  17.     Dim rsPRINT_JOBS As DAO.Recordset
  18.     Dim i As Integer
  19.  
  20.     Set dbJMM = CurrentDb
  21.     Set rsIPAC = dbJMM.OpenRecordset("tblIPAC")
  22.     Set rsPRINT_JOBS = dbJMM.OpenRecordset("PRINT_JOBS")
  23.  
  24.     Do Until rsIPAC.EOF
  25.         Do Until rsPRINT_JOBS.EOF
  26.             If rsPRINT_JOBS!JOB_STATUS = "OPEN" _
  27.                 And rsIPAC!Print = rsPRINT_JOBS!WORK_ORDER_NUM _
  28.                 And rsIPAC!Req_Num = rsPRINT_JOBS!REQUISITION_NUM _
  29.                 And rsPRINT_JOBS!BEST_COST = 0 Then
  30.  
  31.                 Dim curIPACBillAmt As Currency
  32.                 curIPACBillAmt = rsIPAC!Bill_Amt
  33.  
  34.                 rsPRINT_JOBS.Edit
  35.                 rsPRINT_JOBS!BEST_COST = curIPACBillAmt
  36.                 rsPRINT_JOBS!JOB_STATUS = "CLOSED"
  37.                 rsPRINT_JOBS.Update
  38. '               i is the counter to tell you how many records you are updating
  39.                 i = (i + 1)
  40.  
  41.             End If
  42.                 rsPRINT_JOBS.MoveNext
  43.             Loop
  44.  
  45.         rsPRINT_JOBS.MoveFirst
  46.         rsIPAC.MoveNext
  47.         Loop
  48.  
  49.         msgbox "You have updated " & i & " jobs.", , "Notice"
  50.  
  51. '   SQL query to delete all fields from the IPAC table after it has been used.
  52. '   If the table isn't emptied the search would take forever.
  53.     DoCmd.SetWarnings False
  54.     DoCmd.RunSQL "DELETE tblIPAC.[IPACTempID], tblIPAC.[Jacket], tblIPAC.[Req_Num], tblIPAC.[Print], tblIPAC.[Bill_Amt], tblIPAC.[B_A_C], tblIPAC.[Prod_Code], tblIPAC.[IPAC_Cycle], tblIPAC.[Inv_Num], tblIPAC.[Branch], tblIPAC.[FY], tblIPAC.[Quantity], tblIPAC.[Postage], tblIPAC.[Pages], tblIPAC.[Copies], tblIPAC.[Trans], tblIPAC.[Bill_Date], tblIPAC.[Alc_Code], tblIPAC.[IPAC_Ind], tblIPAC.[CC_Ind], tblIPAC.[Filler1], tblIPAC.[Auto_Ind], tblIPAC.[FXK_Crdnum], tblIPAC.[FXK_Invdte], tblIPAC.[FXK_Invnum], tblIPAC.[FXK_Jobref] FROM tblIPAC;"
  55.     DoCmd.SetWarnings True
  56.        Exit Sub
  57.     Else
  58.         msgbox "IPAC not imported!", 48, "Attention"
  59.         Exit Sub
  60.     End If
  61.  
  62.     dbJMM.Close
  63.     rsIPAC.Close
  64.     Set dbJMM = Nothing
  65.     Set rsIPAC = Nothing
  66.  
  67. End Sub
  68.  
Oct 31 '16 #1
12 951
PhilOfWalton
1,430 Expert 1GB
I may be totally wrong, but I have a gut feeling that the whole thing can be done with a query.

Have a look at showing the 2 queries in the QBE grid and linking
rsPRINT_JOBS!BEST_COST with curIPACBillAmt
rsIPAC!Req_Num with rsPRINT_JOBS!REQUISITION_NUM
and setting the criteria to rsPRINT_JOBS!JOB_STATUS = "OPEN" and
And rsPRINT_JOBS!BEST_COST = 0.

Run that as a select query and see if it produces the required results. If so, you can change it into an update query.

Your delete part of your code is simply
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "DELETE tblIPac.* FROM tblIPac"
  2.  
Phil
Oct 31 '16 #2
ADezii
8,834 Expert 8TB
excel sheet I'm importing isn't always complete so I will need to know what records to update manually.
  1. What exactly do you mean when you state that the Sheet 'isn't always complete'?
  2. What are the minimal requirements for Updating a Record?
Oct 31 '16 #3
Thanks for the input Phil! I chose to use code because the guy that set up this database has hundreds of queries forms and tables. It's a tangled mess. Basically I'm paranoid about making that worse. Also I can never seem to get SQL to do what I want, hence the overcomplication of my delete query haha.

I am using three fields from the excel sheet to identify a job in my database then using the bill amount from the spreadsheet to update that job. In my code above I only used two of the fields because the third sometimes is just zeros (on the spreadsheet). I can update the jobs based on two fields but the problem is that the closest thing to a unique identifier on the spreadsheet is a work order number that repeats every year and jacket number repeats every ten years. My table has 22,700 records that date back to 2007. The jacket number begins with the last digit of the current year. So if it can't match all three to a job it's hard to know I have the right one. I would at minimum want to use a msgbox to display which records from the IPAC couldn't be matched, but really I wish I had a better way to validate.

Thanks again for the help!
Nov 1 '16 #4
PhilOfWalton
1,430 Expert 1GB
Believe me, I know the problem with lots of queries, and I wrote them all myself. New report - new query, and almost certainly there would have been an existing query that would have done the job. Nonetheless, I still think that is the way to go, and name your new queries in a way that distinguishes them from the older queries.

As it’s 2016 and your records start in 2007, there should be no duplicated works order numbers. If there are, is there a date within the record that could be used to sort them out?

Is this a “one off” operation, or is the Excel spreadsheet going to be continued to be used?

Back to using a query. By changing relationships between the fields from left to right to equi joins, you can easily see which records have not been matched.

Phil
Nov 1 '16 #5
To re iterate: What I am looking for is a way to show jobs that were not found during the search in the above code.

Phil: Interesting point. Like I said I am open to different methods, I will research joins and try to get a better grasp of them. That may be the best solution.

This spreadsheet will be imported every two weeks. The jacket numbers are about to repeat and the while it's unlikely that the workorder will again coincide with a specific jacket, it is possible.

My main concern is that other than a counter that shows how many records were updated I can't tell what is going on when the code executes. Maybe this is just a phobia I need to get over, but I have considered printing a report to show what has been updated.

Edit: To answer your question about dates: The idea is that a closed job from years ago would be filtered out, reducing the chance of overlap; however the jobs are not often closed. They wait for the payment to process and the bill to come. That can take up to six years.
Nov 1 '16 #6
PhilOfWalton
1,430 Expert 1GB
Sorry to keep asking and not answering.

Is there a good reason for using Excel rather than Access as source of your information?

Is there a possibility of using 2 digits for the year. At least that will only repeat every 100 years and unless you know where to find the elixir of youth, it's unlikely to be your problem.

If you have Skype and would care to share a screen, I could possibly see what you are trying to achieve

Phil
Nov 1 '16 #7
Thanks very much for the offer but my company would not like that at all haha.

Unfortunately this spreadsheet comes from a different source. The numbers are assigned by them, I track our jobs by assigning a new number that is unique and am then left with identifying them individually and manually based on these preassigned numbers. The goal is to automate this process.
Nov 1 '16 #8
ADezii
8,834 Expert 8TB
To re iterate: What I am looking for is a way to show jobs that were not found during the search in the above code.
Why not a simple Else Clause capturing the Unmatched Records, writing these to a Temporary Table?
Nov 1 '16 #9
I could be wrong, but wouldn't that return all failed matches and not just the jobs that never matched?

In other words if it didn't match up with the first thousand records then the else clause would catch all of that as well as the ones that could never be found. Not totally sure on that though...
Nov 1 '16 #10
ADezii
8,834 Expert 8TB
the else clause would catch all of that as well as the ones that could never be found
The Else Clause would return any Records NOT matching the If Criteria, namely:
Expand|Select|Wrap|Line Numbers
  1. NOT (rsPRINT_JOBS!JOB_STATUS = "OPEN" _
  2.                  And rsIPAC!Print = rsPRINT_JOBS!WORK_ORDER_NUM _
  3.                  And rsIPAC!Req_Num = rsPRINT_JOBS!REQUISITION_NUM _
  4.                  And rsPRINT_JOBS!BEST_COST = 0)
P.S. - Sorry if I am missing the point here.
Nov 1 '16 #11
So I added
Expand|Select|Wrap|Line Numbers
  1.  
  2. Else
  3. debug.print rsIPAC!PRINT
  4.  
and it returns the last job's print number repeatedly. I believe that is because the if then statement finds that the last job did not match in the table PRINT_JOBS thousands of times until it did find it, but maybe the immediate screen doesn't hold all of the times it printed.

I will continue looking for a solution, at this point I am mainly documenting in case someone with a similar issue comes across this thread.
Thanks again for all the support.
Nov 2 '16 #12
If anyone comes across this post looking for an answer here it is.

I used DCount with multiple criteria to see how many times a job is found. This is good because it also tells me if the criteria matched more than one time (which would change more than one job). It works and was actually a fairly simple solution. There may be other ways to do it but I couldn't find any type of query that did this. I will probably eventually store the jobs that didn't match to a table to make it easier for the user to work with.

Thanks again for those that helped! If you have a question about this message me and I'll try to help.

Expand|Select|Wrap|Line Numbers
  1. '   Checks to make sure a job in IPAC is in PRINT_JOBS only once
  2. CheckIPAC:
  3.     Do While Not rsIPAC.EOF
  4.         strPrint = rsIPAC!Print
  5.         strReq_Num = rsIPAC!Req_Num
  6.         strCheck = DCount("[WORK_ORDER_NUM] And [REQUISITION_NUM]", "[PRINT_JOBS]", _
  7.         "[WORK_ORDER_NUM] = '" & strPrint & "' And" _
  8.         & "[REQUISITION_NUM] = '" & strReq_Num & "'")
  9. '       strCheck = DCount("[WORK_ORDER_NUM]", "[PRINT_JOBS]", "[WORK_ORDER_NUM] = '" & strPrint & "'")
  10.         If strCheck = 0 Then
  11.             msgbox "A job was not found!" & vbLf & _
  12.                    "Please look up this job to ensure accuracy." & vbLf & vbLf & _
  13.                    "Work Order Num: " & rsIPAC!Print & vbLf & _
  14.                    "Jacket Num: " & rsIPAC!Jacket & vbLf & _
  15.                    "Requisition Num: " & rsIPAC!Req_Num & vbLf & _
  16.                    "Bill Amount: " & rsIPAC!Bill_Amt, 48
  17.                    j = (j + 1)
  18.             Else
  19.                 If strCheck > 1 Then
  20.                     msgbox "A job was found " & strCheck & " times." & vbLf & _
  21.                            "Please look up this job to ensure accuracy." & vbLf & _
  22.                            vbLf & "Work Order Num: " & rsIPAC!Print & vbLf & _
  23.                            "Jacket Num: " & rsIPAC!Jacket & vbLf & _
  24.                            "Requisition Num: " & rsIPAC!Req_Num & vbLf & _
  25.                            "Bill Amount: " & rsIPAC!Bill_Amt, 48
  26.                            j = (j + 1)
  27.                 End If
  28.         End If
  29.         rsIPAC.MoveNext
  30.     Loop
  31.  
  32.     If j > 0 Then
  33.         intCheckAgain = msgbox("The IPAC contained " & j & " jobs that could not be matched." & vbLf & _
  34.                              "You will not have another chance to identify these jobs." & vbLf & _
  35.                              "Whould you like to run this check again?", vbYesNo)
  36.         If intCheckAgain = vbYes Then
  37.             rsIPAC.MoveFirst
  38.             GoTo CheckIPAC
  39.         End If
  40.     End If
  41.  
Nov 3 '16 #13

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

Similar topics

2
by: yoshitha | last post by:
hi, i want to display records in datagrid. strtestids() is a string array. it contains some testids. based on these ids i've to fill the datagrid. i wrote code like this
0
by: Tony | last post by:
vs 2002 - vb - access 2002 - xp - web forms I want to display records, one at a time. I have about 25 fields to display. I've created SQL and retrieved records. I placed data in 25 separate...
3
by: Kai Zhang | last post by:
I am trying to display some database records in datagrid using dataset. the records need to be displayed are couple of thousands, but the records in database that the SQL query needs to exam are...
5
by: dorandoran | last post by:
How do I display records using object oriented method? All I have the link to their api help http://www.e-topco.com/oa/oa_help/OpenAir_SOAP.htm and few example. I am want display all the...
8
by: jawad malik | last post by:
I want that each time i execute query it display records in a way that the top record will be positioned last and so on. First time when i executed query it will display like this name A B ...
0
by: Rahul Metha | last post by:
o Select table from drop down list. o Display records in Grid – Display all records belong to table in grid. o Table Fields – This section will have all the fields which are belongs to table.
5
by: narinas | last post by:
Hello im having 2 tables 1.tbla_can_types(containing type_id,type_name,fac_id) 2.tbla_canteen_rates(containing fac_id,cat_id,type_id,from_time,to_time...) this table is empty. in the load...
3
by: Ann VK | last post by:
I have a table with records like: ID End Price A 20060625 5.70250000000000000000 A 20060725 5.76500000000000000000 A 20060825 5.70438000000000000000 A 20060925 5.71000000000000000000...
0
by: venkatasu | last post by:
I store date in varchar type in a table. unfortunately some users didn't use the date picker and manually entered date erroneously. I want to display records which does not meet the mm/dd/yyyy format...
5
by: jkobsjr | last post by:
I have an input table that I want to query against another table. Column 1 of input table is an ID that matches with a column in the 2nd table. Column 2 is a number that should fall between two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.