Solved

FindFirst vs. Query->OpenRecordset

Posted on 1998-09-01
7
524 Views
Last Modified: 2012-06-27
I have a database that gets updates in the form of a raw text file. The program reads in the first line, parses the data into correct array, then calls the update sub. The update sub looks at the first record, "PrimaryKey", and opens a recordset based on "Where PK= " & arr(0)'PrimaryKey
If nothing is returned, it is assumed this is a new record, and adds it. If a record is returned it is the edited. The code for this is simple, but very slow!!  I am using DBJet btw.  Would it make since to open the recordset as a whole and do a findfirst?  Originally when I wrote this, I was opening the table using the dbOpenTable option, and using a seek. Very fast, but I plan on upsizing someday to SQL, so I must use code structure that will allow this upsize.  That is at least 2 years from now, though, and I need to optimize speed for dbJet.  Thanks.

Info: approxx 145,000 records with 19 fields are updated every day.  Using DAO v2.0, VB6.
Thanks
0
Comment
Question by:redbaron082997
  • 3
  • 2
  • 2
7 Comments
 
LVL 14

Expert Comment

by:waty
Comment Utility
I had to do something like that in a project with MS SQL.
I do as follow :

  I update each row by default.
  If no error was produced, the update was good.
  If an error was produced, I insert the row.

  I made the update and insert using SQL statment
     Update ... Where
     Insert into ...

This was the fastest way. When you will upgrade to SQL Server, you add dbSQLPassThrough to your execute.

If you still want to use your way. You should not use FindFirst wich is not optimized
 
0
 
LVL 4

Expert Comment

by:mcix
Comment Utility
Just a question...

Is your app normally doing more inserts or updates?
Or it about half and half?

Waty proposed a VERY good solution for you if you have mostly updates!
0
 
LVL 4

Expert Comment

by:mcix
Comment Utility
Don't worry too much about your up-size anyway.

In two years Microsoft will have probably started to get away from JET/DAO and will be forcing us into UDA/OLEDB/ADO...
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:redbaron082997
Comment Utility
Actually the app is a 50/50 split at times.  Our stores are sending information about their inventory.  During a normal week, it will be a file showing all inventory that has a changed stock status.  But during promotions, a bunch of sku's are created and must be added.  

I am pretty sure that I can isolate the two events by running a procedure that creates a temp file of just the changes, then another of additions. Would this be much faster, or would the use of an error condition triggering the events sufice?

WATY- I do like your "answer". Thanks.
0
 
LVL 4

Expert Comment

by:mcix
Comment Utility
If you can identify from the import file what is "new" and what is update, I would rip the import file into two files...

Then when you start posting to Access you will only have one database transaction to worry with... And it will either succeed or fail, there will no over-head with testing to see if it is there or not.

If you can't do that, then you are probably about as good as you are going to get with Access...
0
 
LVL 14

Accepted Solution

by:
waty earned 50 total points
Comment Utility
If you can isolate the update and new records, you can improve the adding/update in the database.

I have posted this as answer as you told you liked my answer.
0
 
LVL 1

Author Comment

by:redbaron082997
Comment Utility
thanks!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now