473,794 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Very Slow Loop

Relationship goes Certification can have multiple variations (any single
variation satifies the certification), which require multiple course groups
which require any one of the products assigned to the group.

MS Access.. VBA.. got very many sub relationships and it takes about 30
seconds to see who is certified. But now my problem is I want to go back
through the process and see who is only 1 course group away from being
certified, and if they are only 1 course away which products that means they
need to achieve that course group, thereby achieving the certification.

Since I need to know if only 1 fails it turns into a looping question rather
then a simple SQL statement generation (right?) and this means it takes about
30-100 seconds per a member. I have 7000 members.. ekkkk

Geez.. even if it only takes 2 seconds per a member that means it will be a
routine that takes 4 hours to run. 
Private Sub CertificationRe viewCMD_Click()
'On Error GoTo Err_Certificati onReviewCMD_Cli ck
'Loop through each member (customerid)

'Loop through each certification
'test if certification is already attained by this particular member

'Loop through each variation for each certification
'at end of variation loop if we are only missing 1 coursegroup then
'put the required product id's into the table

'Loop through each course group for each variation

'Loop through each product id for each course group
'if missingcoursegr oup 1 then
'skip to next variation

'Does this member have status(15) for the required product id?
'if yes then goto next course group

'if course group has no matching product ids then
'next course group
'missingcourseg roup + 1

Dim MemberID, CertID, VariationID, CourseGroupID, CurrentProductI D
Dim strSQL
Dim rsVariations
Dim rsCourseGroups
Dim rsCompletedProd ucts 'accredited product ids
Dim MissingCourseGr oup 'number of course groups missing for variation
Dim rsMissingProduc ts 'list products necessary to meet the course group
needs
Dim rsMissingCertif ication 'add products to the proper table
Dim rsMembers 'customer id list
Dim rsCertification s 'all active certifications to test for each member
Dim MemberCounter
Dim rsCertification Acheived 'certification already certified
Dim strTime, MemberStart 'start time for timer
Dim MaxMember

DoCmd.Hourglass True
MemberCounter = 0
strTime = Now
MemberStart = Now

'clear tbl_Certificati onMissing for repopulation
'CurrentDb.Exec ute "Delete * from tbl_Certificati onMissing"
DoCmd.SetWarnin gs False
DoCmd.RunSQL "Delete * from tbl_Certificati onMissing"
DoCmd.SetWarnin gs True

strSQL = "Select * from tbl_Customers" 'this is my 7000 members
Set rsMembers = CurrentDb.OpenR ecordset(strSQL , dbOpenSnapshot, dbReadOnly)
If rsMembers.EOF Then
MsgBox "There are no members in the system."
Else
rsMembers.MoveL ast
MaxMember = rsMembers.Recor dCount
'start progress meter
'http://support.microso ft.com/default.aspx?sc id=kb;EN US;Q103404
'syscmd(1,"text ",100) will set the meter to maximum of 100
'syscmd(2,25) will set current progress to 25/100 or 25% in this example
'syscmd(3) closes meter
'RetVal = SysCmd(1, "Calculatin g Certifications. ..", MaxMember)
rsMembers.MoveF irst
Do Until rsMembers.EOF
MemberID = rsMembers("Cust omerID")
'debug.print "MemberID >" & MemberID & "<"
MemberCounter = MemberCounter + 1
'RetVal = SysCmd(2, MemberCounter)
SysCmd acSysCmdSetStat us, "Calculatin g Member " & MemberCounter & "/" &
MaxMember
strSQL = "SELECT tbl_Schedule_Co urses.ProductID " _
& " FROM tbl_Schedule_Co urses INNER JOIN (tbl_TraineeCou rses INNER JOIN
tbl_Schedule_Da tes " _
& " ON tbl_TraineeCour ses.ScheduleCou rseID = tbl_Schedule_Da tes.
ScheduleCourseI D) ON " _
& " tbl_Schedule_Co urses.ScheduleI D = tbl_Schedule_Da tes.ScheduleID " _
& " WHERE (((tbl_TraineeC ourses.Customer ID)=" & MemberID & ") AND (
(tbl_TraineeCou rses.Status)='1 5'));"
Set rsCompletedProd ucts = CurrentDb.OpenR ecordset(strSQL , dbOpenSnapshot,
dbReadOnly)
If rsCompletedProd ucts.EOF Then
'this member has not completed/accredited any courses skip
Else

strSQL = "Select * from tbl_Certificati ons where active=true"
Set rsCertification s = CurrentDb.OpenR ecordset(strSQL , dbOpenSnapshot,
dbReadOnly)
If rsCertification s.EOF Then
MsgBox "There are no certifications in the system."
Else
Do Until rsCertification s.EOF
CertID = rsCertification s("Certificatio nID")
'debug.print "CertID >" & CertID & "<"

'test if member already has certificate
strSQL = "SELECT tbl_Certified.C ustomerID, tbl_Certified.C ertificateID "
_
& " FROM tbl_Certified WHERE (((tbl_Certifie d.CustomerID)=" & MemberID &
") " _
& " AND ((tbl_Certified .CertificateID) =" & CertID & "));"
Set rsCertification Acheived = CurrentDb.OpenR ecordset(strSQL ,
dbOpenSnapshot, dbReadOnly)
If rsCertification Acheived.EOF Then
'good to test
strSQL = "SELECT TOP 100 PERCENT tbl_Certificati onVariation.Var iationID FROM
" _
& " tbl_Certificati onVariation INNER JOIN tbl_Certificati ons ON " _
& " tbl_Certificati onVariation.Cer tificationID = tbl_Certificati ons.
CertificationID WHERE " _
& "(tbl_Certifica tions.Certifica tionID = " & CertID & ")"
Set rsVariations = CurrentDb.OpenR ecordset(strSQL , dbOpenSnapshot, dbReadOnly)

If rsVariations.EO F Then
MsgBox "There are no variations for certificate id #" & CertID & ""
Else
Do Until rsVariations.EO F
MissingCourseGr oup = 0
VariationID = rsVariations("V ariationID")
'debug.print "Variation ID >" & VariationID & "<"
strSQL = "SELECT TOP 100 PERCENT tbl_Certificati onLink.CourseID FROM
" _
& " tbl_Certificati onVariation INNER JOIN tbl_Certificati onLink ON "
_
& " tbl_Certificati onVariation.Var iationID = tbl_Certificati onLink.
VariationID " _
& " WHERE (tbl_Certificat ionVariation.Va riationID = " & VariationID &
")"
Set rsCourseGroups = CurrentDb.OpenR ecordset(strSQL , dbOpenSnapshot,
dbReadOnly)
If rsCourseGroups. EOF Then
MsgBox "There are no course groups for variation id #" &
VariationID & " within certification id #" & CertID
Else
Do Until rsCourseGroups. EOF
If MissingCourseGr oup 1 Then
'too many CourseGroups missing, just skip
Exit Do
Else
CourseGroupID = rsCourseGroups( "CourseID")
'debug.print "CourseGrou pID >" & CourseGroupID & "<"
NeededCourseGro up = CourseGroupID
strSQL = "SELECT ProductID FROM tbl_CourseLinks WHERE " _
& "(CourseID = " & CourseGroupID & ")"
Set rsProducts = CurrentDb.OpenR ecordset(strSQL ,
dbOpenSnapshot, dbReadOnly)
If rsProducts.EOF Then
MsgBox "There are no products for course group id #"
& CourseGroupID & " for variation id #" & VariationID & " within
certification id #" & CertID
Else
Do Until rsProducts.EOF
CurrentProductI D = rsProducts("Pro ductID")
'debug.print "CurrentProduct ID >" &
CurrentProductI D & "<"
found = False
rsCompletedProd ucts.MoveFirst
'CompletedProdu cts is usually only about a dozen or so at any given time
'check for match between the needed product and
the rsCompletedProd ucts
Do Until rsCompletedProd ucts.EOF
'debug.print "Comparing Products, " &
rsCompletedProd ucts("ProductID ") & " to " & CurrentProductI D & "."
If rsCompletedProd ucts("ProductID ") =
CurrentProductI D Then
'debug.print "FOUND!"
found = True
NeededCourseGro up = Null
Exit Do
End If
rsCompletedProd ucts.MoveNext
Loop
If found Then
Exit Do
End If 'course group just needs one product
match
rsProducts.Move Next
Loop
End If 'rsProducts
If Not found Then
MissingCourseGr oup = MissingCourseGr oup + 1
End If 'was the product needed found?
rsCourseGroups. MoveNext
End If
Loop
End If 'rsCourseGroups
If MissingCourseGr oup = 1 Then
'find the product id to full fill this certification
'MsgBox "Member: " & MemberID & Chr(10) _
& "Certificat ion: " & CertID & Chr(10) _
& "Variation: " & VariationID & Chr(10) _
& "Course Group: " & CourseGroupID & Chr(10)

'simply write the products necessary to achieve the certification, via which
variation, for which course group into a table to reference in the future --
this is the whole point of this sub
strSQL = "SELECT tbl_CourseLinks .CourseID, tbl_CourseLinks .
ProductID " _
& " FROM tbl_CourseLinks WHERE (((tbl_CourseLi nks.CourseID)=" &
CourseGroupID & "));"
Set rsMissingProduc ts = CurrentDb.OpenR ecordset(strSQL ,
dbOpenSnapshot, dbReadOnly)
If rsMissingProduc ts.EOF Then
MsgBox "The course group #" & CoursGroupID & " you require
has no products attached."
Else
Do Until rsMissingProduc ts.EOF
Set rsMissingCertif ication = CurrentDb.OpenR ecordset
("tbl_Certifica tionMissing", dbOpenDynaset, dbSeeChanges)
rsMissingCertif ication.AddNew
rsMissingCertif ication("CertID ") = CertID
rsMissingCertif ication("Variat ionID") = VariationID
rsMissingCertif ication("Produc tID") =
rsMissingProduc ts("ProductID" )
rsMissingCertif ication("Custom erID") = MemberID
rsMissingCertif ication("Course GroupID") =
CourseGroupID
rsMissingCertif ication.Update
rsMissingProduc ts.MoveNext
Loop
rsMissingCertif ication.Close
Set rsMissingCertif ication = Nothing
End If 'rsMissingProdu cts
rsMissingProduc ts.Close
Set rsMissingProduc ts = Nothing
End If
rsVariations.Mo veNext
Loop
End If 'variations
rsVariations.Cl ose
Set rsVariations = Nothing
rsCourseGroups. Close
Set rsCourseGroups = Nothing
End If 'rsCertificatio nAcheived
rsCertification Acheived.Close
Set rsCertification Acheived = Nothing
rsCertification s.MoveNext
Loop
End If 'rsCertificatio ns
rsCertification s.Close
Set rsCertification s = Nothing

End If 'rsCompletedPro ducts
rsCompletedProd ucts.Close
Set rsCompletedProd ucts = Nothing

Debug.Print "Total Time for Member ID#" & MemberID & ": " & DateDiff("s",
MemberStart, Now) & " seconds, thank you for your patience."
'this is typically about 30-100 seconds per a member
MemberStart = Now
rsMembers.MoveN ext
Loop
End If 'rsMembers
rsMembers.Close
Set rsMembers = Nothing
Exit_Certificat ionReviewCMD_Cl ick:
MsgBox "Total Time: " & DateDiff("n", strTime, Now) & " minutes, thank
you for your patience."
'RetVal = SysCmd(3)
SysCmd acSysCmdClearSt atus ' clear my text from the status bar
DoCmd.Hourglass False
Exit Sub

Err_Certificati onReviewCMD_Cli ck:
MsgBox Err.Description
Resume Exit_Certificat ionReviewCMD_Cl ick

End Sub

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200707/1

Jul 12 '07 #1
2 3962
Well I found some posts about the DoEvents tag, included that in a few loops
and things seemed a bit better.

Now I get to 276/6920 before Error 3151 ODBC connection failed.

Using ODBC to connect to a MS SQL backend with linked tables.

Best course of action?
a) create local copies of the tables for no odbc connection errors
b) continue to try and improve the loop efficiency (perhaps add doevents to
all loops?)
c) other recommendations ?

Thanks,
Clinton

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200707/1

Jul 12 '07 #2
I mean no offense but this is a nightmare :)

Could you please post more examples of your data, here's what I
understood (and/or imagine) please correct me:

Being Certified means having completed a Variation.

A Variation is a list of Courses to be taken.

A person can complete a Certification by choosing which Variation s/he
will complete. (For example a Certification in Access could mean
taking three long courses (variation A) or ten short courses
(variation B)

A person can possibly have multiple Certifications going on at the
same time.

You're interested in finding out which persons are only one course
away of completing a variation.

Somewhere you talk about "Products", they seem to be related to the
courses somehow? That part I didn't understand at all.

For added performance, yes, by all means you should import the tables
and build relevant indexes on them. (On all "ID" columns... i.e.
VariationID, CourseID..)

Regards
C.
On Jul 12, 1:04 pm, "LostDevelo per via AccessMonster.c om" <u9481@uwe>
wrote:
Well I found some posts about the DoEvents tag, included that in a few loops
and things seemed a bit better.

Now I get to 276/6920 before Error 3151 ODBC connection failed.

Using ODBC to connect to a MS SQL backend with linked tables.

Best course of action?
a) create local copies of the tables for no odbc connection errors
b) continue to try and improve the loop efficiency (perhaps add doevents to
all loops?)
c) other recommendations ?

Thanks,
Clinton

--
Message posted via AccessMonster.c omhttp://www.accessmonst er.com/Uwe/Forums.aspx/databases-ms-access/2007...

Jul 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
412
by: Juha Kettunen | last post by:
Hi I don't know if I am using right words (bit-number), but this is what I mean: You can set a 64 bit number: unsigned long a; Now you can use binary operators to manipulate variable a (for example
1
2243
by: David Lawson | last post by:
The line indicated below from my php script is very slow (about 10 seconds). I have this field indexed so I thought that it would be much faster. Could someone tell me what might be wrong? I'm also including the dump of the table definitions. This is a cd cataloging database. Right now the filenames table is empty and I'm trying to populate it, but at the rate it's going it would take days. I have about 700,000 records in the 'files'...
11
17578
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time to load making any kind linkage with my Access data virtually useless. I have the MySQL driver setup in as a USER DSN. The MySQL data is sitting out on a server and the Access database is running locally. The network connection is very...
5
2735
by: Kurt Bauer | last post by:
I have an ASP group calendar application which pulls calendar data from Exchange via webdav into an XML string. I then loop the XML nodes to populate a collection of appointments. Finally I use the appointment collection to populate the calendar control. The performance getting the XML data is fine, but loading the data into the collection is slow. My question/problem is should I be using the collection, a dataset, or something else to...
2
8276
by: Robert Hooker | last post by:
Hi, I'm curious to know if I'm doing something wrong here, or if this is just mind-numbingly slow for a reason. In a simple WindowsFormsApplication: public Form1() { // Required for Windows Form Designer support
5
4179
by: PH | last post by:
Hi guys; I got a single processor computer, running an application that launches 2 threads. Each of these threads listens for incoming connections in a specific port, so there is a Loop . Until inside each of them.
9
8683
by: dan | last post by:
within a loop i am building a sql insert statement to run against my (programatically created) mdb. it works but it seems unreasonably SLOW! Sorry, dont have the code here but the jist is very standard (I think!); e.g: # get connection loop
2
2257
by: giannis | last post by:
At the below code i search for a value of a field of a BindingSource and when not found i search for the 40 earlier values inside a Loop. At the Access VB i used the same Loop with the command "DoCmd.FindRecord" and the rapidity was very much big. Now at the VB this Loop be late very much (it is very slow). :( Why this happens and how can i resolve this problem ? Is there any other way to make this loop more fast ?
0
1154
by: pooky333 | last post by:
Hello! Please help someone... I am still at work and completely stumped. I am a relative beginner at VB and have put together some apparently awful code (as shown below). It is to compare two incredibly huge lists of strings (which might duplicate if I take out things like - (not sure if relevant!)), find matches and entering text next to each one. It is very slow and completes a loop about 4 times a minute (yes i have timed it). the annoying...
0
9671
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10433
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10161
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7538
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.