I'm stumped and am hoping someone can help me. Some time ago I added a private sub to a subform that performs a DLookup in a query that filters on two fields in the subform active record and adds information from the query to a field in the subforms active record and based on what it adds it will update another field before moving on to the next record and then loops until it reaches the end of the subform. I did this because I couldn't figure out how to achieve what I needed Access to do any other way and although it was slow it did the job. The problem is I created this database using Access 2007 and recently upgraded to Access 2010. When I run the private sub it starts just fine but then seems to cause the database to stop running after about 300 to 400 records. I typically run this for between 30,000 and 60,000 records.
Is there an alternative to achieve what I need access to do, possibly one that will work quicker? If so, can you explain what I need to do? Any help is very much appreciated. Here are the details.
Query and Forms:
- Query is called "Dispatch Analysis Auto Rank"
- Form is called "Dispatch Analysis"
- Subform is called "Dispatch Analysis subform"
The query has the following fields:
- ID (key)
- Store #
- Request Type
- Vendor #
- Auto Rank (formula)
- Trip + 3 Hrs
- Standard Hourly Rate Reg
The subform has the following fields:
- ID (key)
- Store #
- Request Type
- Vendor #
- Rank
- Old Rank
- Existing Rank
- Action
- Trip + 3 Hrs
- Standard Hourly Rate Reg
Here is what the query is doing:
- It is filtering on Store # in the subforms active record "criteria is [Forms]![Dispatch Analysis]![Dispatch Analysis subform].[Form]![Store #]"
- It is filtering on Request Type in the subforms active record "criteria is [Forms]![Dispatch Analysis]![Dispatch Analysis subform].[Form]![Request Type]"
- It then assigns a sequential number called Auto Rank based on the ID "formula is DCount("ID","Dispatch Analysis Auto Rank","ID <= " & [ID])"
- Trip + 3 Hrs criteria is >0
- Standard Hourly Rate Reg criteria is >0
By performing a DLookup on this query I'm able to assign a unique number (Auto Rank) to each vendor for each Store #/Request Type and assign an action based on the If statements if there is a trip +3 Hrs and a Standard Hourly Rate Reg. The Auto Rank by Store #/Request Type is the most important part of this.
Here is the subform sub I run by double clicking on the Rank field I want to start adding the Auto Rank from the query to the Rank in the subform and update the Action.
Private Sub Rank_DblClick(Cancel As Integer)
If MsgBoxYesNo(RunAutoRankYesNo) Then
While Me.CurrentRecord < Me.Recordset.RecordCount
If Me.Trip___3_Hrs > 1 And Me.Standard_Hourly_Rate_Reg > 1 Then
Me![Rank] = DLookup("[Auto Rank]", "Dispatch Analysis Auto Rank", "[ID]=Forms![Dispatch Analysis]![Dispatch Analysis subform]![ID]")
If IsNull(Me.Rank) Then
Me.Action = Null
ElseIf Me.Rank > 0 And Me.Existing_Rank = "Yes" And Me.Rank <> Me.Old_Rank Then
Me.Action = "Change"
ElseIf Me.Rank > 0 And Me.Existing_Rank = "Yes" And Me.Rank = Me.Old_Rank Then
Me.Action = Null
ElseIf Me.Rank > 0 And Me.Existing_Rank = "No" Then
Me.Action = "Add"
End If
Else
Me.Rank = Null
Me.Action = Null
End If
DoCmd.GoToRecord Record:=acNext
Wend
MsgBoxOKOnly AutoRankComplete
End If
End Sub
Can anyone help me with this? Is there alternative like a RecordSetClone? If so, how would I write this?
Thank you in advance!
Daniel