Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with code

Status
Not open for further replies.

sfrope1

Technical User
May 17, 2003
6
0
0
US
I have the following code and it works and generates my order, but does not number my roping order correctly. Generally does not begin with one and then I have a duplicate number, say like 2 4's. Is there any way to make this come back starting with 1. Any help would be appreciated:

Private Sub cmdGenerateRopingOrder_Click()

Dim rsRegistrations As ADODB.Recordset
Dim rsLastSlot As ADODB.Recordset
Dim rsExists As ADODB.Recordset
Dim rsnumberofslots As Integer
Dim X As Integer
Dim intHeaderID As Integer
Dim intNumberOfSlots As Integer
Dim intBestSlotNo As Integer
Dim intLastSlot As Integer


'Delete the roping orders
CurrentProject.Connection.Execute "UPDATE tblRegistration SET RopingOrder = 0 WHERE EventID = " & Me!EventID

'For each registration
Set rsRegistrations = New Recordset
Set rsLastSlot = New Recordset
Set rsExists = New Recordset

rsRegistrations.Open "SELECT * FROM tblRegistration WHERE EventID = " & Me!EventID & " ORDER BY RegistrationID", CurrentProject.Connection, adOpenStatic, adLockReadOnly
rsRegistrations.MoveLast
intNumberOfSlots = rsRegistrations.RecordCount
rsRegistrations.Close

rsRegistrations.Open "SELECT * FROM tblRegistration WHERE EventID = " & Me!EventID & " ORDER BY RegistrationID", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
Do Until rsRegistrations.EOF

'Get Header
intHeaderID = rsRegistrations("Header")

'Get LastAvailable ropingorder number
rsLastSlot.Open "SELECT RopingOrder FROM tblRegistration WHERE EventID = " & Me!EventID & " AND Header = " & intHeaderID & " AND RopingOrder > 0 ORDER BY RopingOrder", CurrentProject.Connection, adOpenStatic, adLockReadOnly
If rsLastSlot.RecordCount = 0 Then
'Go from lastslot forward to find an open slot
For X = intNumberOfSlots To 1 Step -1
rsExists.Open "SELECT * FROM tblRegistration WHERE EventID = " & Me!EventID & " and RopingOrder = " & X, CurrentProject.Connection, adOpenStatic, adLockReadOnly
If rsExists.RecordCount = 0 Then
intBestSlotNo = X
rsExists.Close
Exit For
End If
rsExists.Close
Next X

Else
'add minimumspacing to LastOfRopingOrder
intLastSlot = rsLastSlot("RopingOrder") - Me!MinimumSpacing
For X = intLastSlot To 1 Step -1
rsExists.Open "SELECT * FROM tblRegistration WHERE EventID = " & Me!EventID & " and RopingOrder = " & X, CurrentProject.Connection, adOpenStatic, adLockReadOnly
If rsExists.RecordCount = 0 Then
intBestSlotNo = X
rsExists.Close
Exit For
End If
rsExists.Close
Next X

End If

rsLastSlot.Close

'set this registration's RopingOrder = BestSlotNo

rsRegistrations("RopingOrder") = intBestSlotNo
rsRegistrations.Update

rsRegistrations.MoveNext
'Loop
Loop

rsRegistrations.Close

MsgBox "Roping Order Generated.", vbOKOnly

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top