Hello there!
I'm probably being stupid here, but I'm really struggling with two nested For ... Next loops.
The DB I have is a waiting list simulator. It has an amount of people waiting in 53 weekly brackets (0 to 52), for each Specialty (19 of them). It takes the starting point from another DB on our system (linked table), then in the table tbl_Patients_To_Remove you can specify how many people will be removed from the waiting list and added to the waiting list for each of the weekly brackets and specialty.
This is then compared to the original starting list, and the patient amount calculated for each week and appended to the table tbl1stAttempt.
This was working absolutely fine without the specialty in there, but now it's messed my loop up.
I think I've figured out why it's gone wrong, just dont know how to rectify it!
Here's the code for the loops:
As far as I can tell the problem occurs because it is not looping in sequence, i.e, the loop is not going through all the specialties in the correct order, just as they appear in the list. The calculation for the patient amount is then skewed because of this.
Anyone got any ideas on how I can fix this? I'm at a dead end completely.
I can upload the DB if necessary.
Regards,
Ben
I'm probably being stupid here, but I'm really struggling with two nested For ... Next loops.
The DB I have is a waiting list simulator. It has an amount of people waiting in 53 weekly brackets (0 to 52), for each Specialty (19 of them). It takes the starting point from another DB on our system (linked table), then in the table tbl_Patients_To_Remove you can specify how many people will be removed from the waiting list and added to the waiting list for each of the weekly brackets and specialty.
This is then compared to the original starting list, and the patient amount calculated for each week and appended to the table tbl1stAttempt.
This was working absolutely fine without the specialty in there, but now it's messed my loop up.
I think I've figured out why it's gone wrong, just dont know how to rectify it!
Here's the code for the loops:
Code:
Private Sub Command3_Click()
Dim DB As Database
Dim RST As Recordset
Dim Pats
Dim Pats2
Dim NewPats
Dim R
Dim X
Dim SID
Set DB = CurrentDb
Set RST = DB.OpenRecordset("tbltemp")
SID = [Spec_ID]
X = [Weeks Waited]
For SID = 1 To 19 Step 1
For X = 52 To 0 Step -1
Pats = [Patients Waiting]
Pats2 = 0
Start:
If Pats >= 0 Then
'CurrentDb.Execute "UPDATE tblTemp SET [Patients Waiting]=" & Pats & " WHERE [Weeks Waited] = " & Me.Weeks_Waitedtxt & " AND [Spec_ID] =" & Me.Spec_IDtxt
DoCmd.GoToRecord , , acNext
ElseIf Pats < 0 Then
Line_1: R = (Pats * -1)
Pats = 0
Debug.Print "Patients Waiting: " & [Patients Waiting] & " Weeks Waited: " & [Weeks Waited] & " Spec Code: " & [Spec_ID]
DoCmd.GoToRecord , , acNext
Pats = ([Patients Waiting] - R)
If Pats >= 0 Then
CurrentDb.Execute "UPDATE tblTemp SET [Patients Waiting]=" & Pats & " WHERE [Weeks Waited] = " & Me.Weeks_Waitedtxt & " AND [Spec_ID] =" & Me.Spec_IDtxt
Else:
GoTo Line_1
End If
End If
Next X
Next SID
'DoCmd.RunMacro "mcrmanipulatedata"
MsgBox "Data Manipulation Complete", vbInformation = vbOKOnly
DoCmd.Close acForm, "Form1"
End Sub
As far as I can tell the problem occurs because it is not looping in sequence, i.e, the loop is not going through all the specialties in the correct order, just as they appear in the list. The calculation for the patient amount is then skewed because of this.
Anyone got any ideas on how I can fix this? I'm at a dead end completely.
I can upload the DB if necessary.
Regards,
Ben