I have code in a form that loops based on priority that is selected on combo boxes. Those boxes are linked to a simple table that has priority 1-5. What I am trying to do is to make an option to not consider a site as a priority. I basically want to make the priority 0 and skip that site. This code includes some date slection and other things. I'm just not sure where and how to make it consider a 0 priority.
Private Sub Command32_Click()
Dim db As Database
Dim frm As Form
Dim rec As Recordset
Dim mySQL As String
'These values are pulled from a table or form
Dim HiresNeeded As Double '# of guides to hire per week
Dim StartDate As Double 'start date of hiring time frame
Dim EndDate As Double 'end date of hiring time frame
Dim Site As String
Dim Priority As Double
Dim LoopDate As Date
Dim StatCap As Double 'number of stations available in the call center
Dim Util As Double 'stations currently in use
Dim StUtil As Double '# of guides that can be assigned to a station
Dim SzLimit As Double 'Size new hire class is limited to
'Calculated Values
Dim HireCap As Double '# of guides have seats to hiring
Dim HireAbility As Double '# of guides can hire given class size limit
Dim ToHire As Double '# of guides to hire on a given date in a given site
DoCmd.SetWarnings no
DoCmd.RunSQL "UPDATE tblResults SET tblResults.[Indianapolis Hire] = 0, tblResults.[Saint John Hire] = 0, tblResults.[Mexico Hire] = 0, tblResults.[Cork Hire] = 0, tblResults.[Manila Hire] = 0, tblResults.[Indianapolis Cap] = 0, tblResults.[Saint John Cap] = 0, tblResults.[Mexico Cap] = 0, tblResults.[Cork Cap] = 0, tblResults.[Manila Cap] = 0, tblResults.[Hires Needed] = 0, tblResults.[Remainder]= 0"
Set db = CurrentDb
Set frm = Forms!FrmStaffingModel_copy
StartDate = frm.txtStartDate
EndDate = frm.EndDate
'Update tblSiteData with priority data entered on form
mySQL = "SELECT tblSiteData.Site, tblSiteData.[Seating Capacity], tblSiteData.[Station Utiliz], tblSiteData.[Class Size limiter], tblSiteData.Priority FROM tblSiteData WHERE (((tblSiteData.Site)='Indy'))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec!Priority = txtIndypriority
rec.Update
rec.Close
mySQL = "SELECT tblSiteData.Site, tblSiteData.[Seating Capacity], tblSiteData.[Station Utiliz], tblSiteData.[Class Size limiter], tblSiteData.Priority FROM tblSiteData WHERE (((tblSiteData.Site)='Saint John'))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec!Priority = txtSaintJohnpriority
rec.Update
rec.Close
mySQL = "SELECT tblSiteData.Site, tblSiteData.[Seating Capacity], tblSiteData.[Station Utiliz], tblSiteData.[Class Size limiter], tblSiteData.Priority FROM tblSiteData WHERE (((tblSiteData.Site)='Mexico'))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec!Priority = txtMexicopriority
rec.Update
rec.Close
mySQL = "SELECT tblSiteData.Site, tblSiteData.[Seating Capacity], tblSiteData.[Station Utiliz], tblSiteData.[Class Size limiter], tblSiteData.Priority FROM tblSiteData WHERE (((tblSiteData.Site)='Cork'))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec!Priority = txtCorkPriority
rec.Update
rec.Close
mySQL = "SELECT tblSiteData.Site, tblSiteData.[Seating Capacity], tblSiteData.[Station Utiliz], tblSiteData.[Class Size limiter], tblSiteData.Priority FROM tblSiteData WHERE (((tblSiteData.Site)='Manila'))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec!Priority = txtManilaPriority
rec.Update
rec.Close
'Begin Calculations
LoopDate = StartDate
Do
mySQL = "SELECT Sheet1_x65.Date, Sheet1_x65.HiresNeeded FROM Sheet1_x65 WHERE (((Sheet1_x65.Date)=#" & LoopDate & "#))"
Set rec = db.OpenRecordset(mySQL)
HiresNeeded = rec!HiresNeeded
rec.Close
mySQL = "SELECT tblResults.Week, tblResults.[Hires Needed] FROM tblResults WHERE (((tblResults.Week)=#" & LoopDate & "#))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec![Hires Needed] = HiresNeeded
rec.Update
rec.Close
Priority = 1
Do
mySQL = "SELECT tblSiteData.Site, tblSiteData.[Seating Capacity], tblSiteData.[Station Utiliz], tblSiteData.[Class Size limiter], tblSiteData.Priority FROM tblSiteData WHERE (((tblSiteData.Priority)=" & Priority & "))"
Set rec = db.OpenRecordset(mySQL)
StatCap = rec![Seating Capacity]
StUtil = rec![Station Utiliz]
SzLimit = rec![Class Size limiter]
Site = rec![Site]
rec.Close
'***Will need to add option for varying date!***
mySQL = "SELECT Sheet1_x65.date, Sheet1_x65.cork, Sheet1_x65.indy, Sheet1_x65.saj, Sheet1_x65.mex, Sheet1_x65.manila FROM Sheet1_x65 WHERE (((Sheet1_x65.date)=#" & LoopDate & "#))"
Debug.Print mySQL
Set rec = db.OpenRecordset(mySQL)
Select Case Site
Case "Indy"
Util = rec![indy]
Case "Saint John"
Util = rec![saj]
Case "Mexico"
Util = rec![mex]
Case "Cork"
Util = rec![Cork]
Case "Manila"
Util = rec![manila]
End Select
HireCap = (StatCap * StUtil) - Util
If HireCap > 0 Then
If HireCap > SzLimit Then HireAbility = SzLimit Else HireAbility = HireCap
ElseIf HireCap <= 0 Then HireAbility = 0
End If
If HiresNeeded > 0 Then
If HireAbility < HiresNeeded Then ToHire = HireAbility Else ToHire = HiresNeeded
ElseIf HiresNeeded <= 0 Then ToHire = 0
End If
'***Need to add date varying capability
mySQL = "SELECT tblResults.Week, tblResults.[Indianapolis Cap], tblResults.[Saint John Cap], tblResults.[Mexico Cap], tblResults.[Manila Cap], tblResults.[Cork Cap] FROM tblResults WHERE (((tblResults.[Week])=#" & LoopDate & "#))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
Select Case Site
Case "Indy"
rec![Indianapolis Cap] = HireAbility
Case "Saint John"
rec![Saint John Cap] = HireAbility
Case "Mexico"
rec![Mexico Cap] = HireAbility
Case "Cork"
rec![Cork Cap] = HireAbility
Case "Manila"
rec![Manila Cap] = HireAbility
End Select
rec.Update
rec.Close
mySQL = "SELECT tblResults.Week, tblResults.[Indianapolis Hire], tblResults.[Saint John Hire], tblResults.[Mexico Hire], tblResults.[Manila Hire], tblResults.[Cork Hire] FROM tblResults WHERE (((tblResults.[Week])=#" & LoopDate & "#))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
Select Case Site
Case "Indy"
rec![Indianapolis Hire] = ToHire
Case "Saint John"
rec![Saint John Hire] = ToHire
Case "Mexico"
rec![Mexico Hire] = ToHire
Case "Cork"
rec![Cork Hire] = ToHire
Case "Manila"
rec![Manila Hire] = ToHire
End Select
rec.Update
rec.Close
HiresNeeded = HiresNeeded - ToHire
Priority = Priority + 1
Loop Until Priority = 6
mySQL = "SELECT tblResults.Week, tblResults.Remainder FROM tblResults WHERE (((tblResults.Week)=#" & LoopDate & "#))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec!Remainder = HiresNeeded
rec.Update
rec.Close
LoopDate = LoopDate + 7
Loop Until LoopDate = EndDate + 7
frm.listresults.RowSource = ("SELECT tblResults.Week, tblResults.[Hires Needed], tblResults.[Indianapolis Cap], tblResults.[Saint John Cap], tblResults.[Mexico Cap], tblResults.[Manila Cap], tblResults.[Cork Cap], tblResults.[Indianapolis Hire], tblResults.[Saint John Hire], tblResults.[Mexico Hire], tblResults.[Manila Hire], tblResults.[Cork Hire], tblResults.Remainder FROM tblResults")
frm.listresults.Requery
MsgBox "Finished running!", vbInformation
End Sub
Private Sub Command32_Click()
Dim db As Database
Dim frm As Form
Dim rec As Recordset
Dim mySQL As String
'These values are pulled from a table or form
Dim HiresNeeded As Double '# of guides to hire per week
Dim StartDate As Double 'start date of hiring time frame
Dim EndDate As Double 'end date of hiring time frame
Dim Site As String
Dim Priority As Double
Dim LoopDate As Date
Dim StatCap As Double 'number of stations available in the call center
Dim Util As Double 'stations currently in use
Dim StUtil As Double '# of guides that can be assigned to a station
Dim SzLimit As Double 'Size new hire class is limited to
'Calculated Values
Dim HireCap As Double '# of guides have seats to hiring
Dim HireAbility As Double '# of guides can hire given class size limit
Dim ToHire As Double '# of guides to hire on a given date in a given site
DoCmd.SetWarnings no
DoCmd.RunSQL "UPDATE tblResults SET tblResults.[Indianapolis Hire] = 0, tblResults.[Saint John Hire] = 0, tblResults.[Mexico Hire] = 0, tblResults.[Cork Hire] = 0, tblResults.[Manila Hire] = 0, tblResults.[Indianapolis Cap] = 0, tblResults.[Saint John Cap] = 0, tblResults.[Mexico Cap] = 0, tblResults.[Cork Cap] = 0, tblResults.[Manila Cap] = 0, tblResults.[Hires Needed] = 0, tblResults.[Remainder]= 0"
Set db = CurrentDb
Set frm = Forms!FrmStaffingModel_copy
StartDate = frm.txtStartDate
EndDate = frm.EndDate
'Update tblSiteData with priority data entered on form
mySQL = "SELECT tblSiteData.Site, tblSiteData.[Seating Capacity], tblSiteData.[Station Utiliz], tblSiteData.[Class Size limiter], tblSiteData.Priority FROM tblSiteData WHERE (((tblSiteData.Site)='Indy'))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec!Priority = txtIndypriority
rec.Update
rec.Close
mySQL = "SELECT tblSiteData.Site, tblSiteData.[Seating Capacity], tblSiteData.[Station Utiliz], tblSiteData.[Class Size limiter], tblSiteData.Priority FROM tblSiteData WHERE (((tblSiteData.Site)='Saint John'))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec!Priority = txtSaintJohnpriority
rec.Update
rec.Close
mySQL = "SELECT tblSiteData.Site, tblSiteData.[Seating Capacity], tblSiteData.[Station Utiliz], tblSiteData.[Class Size limiter], tblSiteData.Priority FROM tblSiteData WHERE (((tblSiteData.Site)='Mexico'))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec!Priority = txtMexicopriority
rec.Update
rec.Close
mySQL = "SELECT tblSiteData.Site, tblSiteData.[Seating Capacity], tblSiteData.[Station Utiliz], tblSiteData.[Class Size limiter], tblSiteData.Priority FROM tblSiteData WHERE (((tblSiteData.Site)='Cork'))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec!Priority = txtCorkPriority
rec.Update
rec.Close
mySQL = "SELECT tblSiteData.Site, tblSiteData.[Seating Capacity], tblSiteData.[Station Utiliz], tblSiteData.[Class Size limiter], tblSiteData.Priority FROM tblSiteData WHERE (((tblSiteData.Site)='Manila'))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec!Priority = txtManilaPriority
rec.Update
rec.Close
'Begin Calculations
LoopDate = StartDate
Do
mySQL = "SELECT Sheet1_x65.Date, Sheet1_x65.HiresNeeded FROM Sheet1_x65 WHERE (((Sheet1_x65.Date)=#" & LoopDate & "#))"
Set rec = db.OpenRecordset(mySQL)
HiresNeeded = rec!HiresNeeded
rec.Close
mySQL = "SELECT tblResults.Week, tblResults.[Hires Needed] FROM tblResults WHERE (((tblResults.Week)=#" & LoopDate & "#))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec![Hires Needed] = HiresNeeded
rec.Update
rec.Close
Priority = 1
Do
mySQL = "SELECT tblSiteData.Site, tblSiteData.[Seating Capacity], tblSiteData.[Station Utiliz], tblSiteData.[Class Size limiter], tblSiteData.Priority FROM tblSiteData WHERE (((tblSiteData.Priority)=" & Priority & "))"
Set rec = db.OpenRecordset(mySQL)
StatCap = rec![Seating Capacity]
StUtil = rec![Station Utiliz]
SzLimit = rec![Class Size limiter]
Site = rec![Site]
rec.Close
'***Will need to add option for varying date!***
mySQL = "SELECT Sheet1_x65.date, Sheet1_x65.cork, Sheet1_x65.indy, Sheet1_x65.saj, Sheet1_x65.mex, Sheet1_x65.manila FROM Sheet1_x65 WHERE (((Sheet1_x65.date)=#" & LoopDate & "#))"
Debug.Print mySQL
Set rec = db.OpenRecordset(mySQL)
Select Case Site
Case "Indy"
Util = rec![indy]
Case "Saint John"
Util = rec![saj]
Case "Mexico"
Util = rec![mex]
Case "Cork"
Util = rec![Cork]
Case "Manila"
Util = rec![manila]
End Select
HireCap = (StatCap * StUtil) - Util
If HireCap > 0 Then
If HireCap > SzLimit Then HireAbility = SzLimit Else HireAbility = HireCap
ElseIf HireCap <= 0 Then HireAbility = 0
End If
If HiresNeeded > 0 Then
If HireAbility < HiresNeeded Then ToHire = HireAbility Else ToHire = HiresNeeded
ElseIf HiresNeeded <= 0 Then ToHire = 0
End If
'***Need to add date varying capability
mySQL = "SELECT tblResults.Week, tblResults.[Indianapolis Cap], tblResults.[Saint John Cap], tblResults.[Mexico Cap], tblResults.[Manila Cap], tblResults.[Cork Cap] FROM tblResults WHERE (((tblResults.[Week])=#" & LoopDate & "#))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
Select Case Site
Case "Indy"
rec![Indianapolis Cap] = HireAbility
Case "Saint John"
rec![Saint John Cap] = HireAbility
Case "Mexico"
rec![Mexico Cap] = HireAbility
Case "Cork"
rec![Cork Cap] = HireAbility
Case "Manila"
rec![Manila Cap] = HireAbility
End Select
rec.Update
rec.Close
mySQL = "SELECT tblResults.Week, tblResults.[Indianapolis Hire], tblResults.[Saint John Hire], tblResults.[Mexico Hire], tblResults.[Manila Hire], tblResults.[Cork Hire] FROM tblResults WHERE (((tblResults.[Week])=#" & LoopDate & "#))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
Select Case Site
Case "Indy"
rec![Indianapolis Hire] = ToHire
Case "Saint John"
rec![Saint John Hire] = ToHire
Case "Mexico"
rec![Mexico Hire] = ToHire
Case "Cork"
rec![Cork Hire] = ToHire
Case "Manila"
rec![Manila Hire] = ToHire
End Select
rec.Update
rec.Close
HiresNeeded = HiresNeeded - ToHire
Priority = Priority + 1
Loop Until Priority = 6
mySQL = "SELECT tblResults.Week, tblResults.Remainder FROM tblResults WHERE (((tblResults.Week)=#" & LoopDate & "#))"
Set rec = db.OpenRecordset(mySQL)
rec.Edit
rec!Remainder = HiresNeeded
rec.Update
rec.Close
LoopDate = LoopDate + 7
Loop Until LoopDate = EndDate + 7
frm.listresults.RowSource = ("SELECT tblResults.Week, tblResults.[Hires Needed], tblResults.[Indianapolis Cap], tblResults.[Saint John Cap], tblResults.[Mexico Cap], tblResults.[Manila Cap], tblResults.[Cork Cap], tblResults.[Indianapolis Hire], tblResults.[Saint John Hire], tblResults.[Mexico Hire], tblResults.[Manila Hire], tblResults.[Cork Hire], tblResults.Remainder FROM tblResults")
frm.listresults.Requery
MsgBox "Finished running!", vbInformation
End Sub