[COLOR="SeaGreen"]' Force save of unsaved data[/COLOR]
Me.Dirty = False
[COLOR="SeaGreen"]'Ensure at least one wine has been entered[/COLOR]
If DCount("numberbtls", "tbl_winein") = 0 Then
MsgBox "Please enter at least one wine to be loaded"
Exit Sub
End If
[COLOR="SeaGreen"]' Check for wine with no bottle count[/COLOR]
If DCount("numberbtls", "tbl_winein") > 0 And DMin("numberbtls", "tbl_winein") = 0 Then
MsgBox "There is a wine(s) without a number of bottles. Please correct this before proceeding", vbOKOnly
Exit Sub
End If
[COLOR="SeaGreen"]' Start Allocation Process[/COLOR]
Dim WineCnt As Integer [COLOR="SeaGreen"] ' Count of wines to be loaded[/COLOR]
Dim BtlCntIn As Integer [COLOR="SeaGreen"]' Count of bottles for current wine[/COLOR]
Dim strZone As Integer [COLOR="SeaGreen"]' Current Zone id[/COLOR]
Dim strZonePrior As String [COLOR="SeaGreen"] ' Current Zone Priority[/COLOR]
Dim strZoneID As String
Dim strCellID As Integer [COLOR="SeaGreen"] ' Cell Id to populate[/COLOR]
Dim strWineID As Integer [COLOR="SeaGreen"]' Current wine ID[/COLOR]
DoCmd.Close [COLOR="SeaGreen"]' Close form[/COLOR]
WineCnt = DCount("numberbtls", "tbl_winein")
While WineCnt > 0
BtlCntIn = DLookup("NumberBtls", "tbl_winein", "wineid = " & DMin("wineid", "tbl_winein", "Btlcnt = " & DMin("btlcnt", "tbl_winein")))
strZone = DLookup("ZoneID", "tbl_winein", "wineid = " & DMin("wineid", "tbl_winein", "Btlcnt = " & DMin("btlcnt", "tbl_winein")))
strWineID = DLookup("WineID", "tbl_winein", "wineid = " & DMin("wineid", "tbl_winein", "Btlcnt = " & DMin("btlcnt", "tbl_winein")))
Select Case strZone [COLOR="SeaGreen"] ' Assign zone sort priority[/COLOR]
Case 1
strZonePrior = "Priority1"
Case 2
strZonePrior = "Priority2"
Case 3
strZonePrior = "Priority3"
Case 4
strZonePrior = "Priority4"
End Select
While BtlCntIn > 0 [COLOR="SeaGreen"]' Allocate wines[/COLOR]
strZoneID = DMin(strZonePrior, "tbl_cells", "isnull(wineid)")
strCellID = DLookup("CellID", "tbl_cells", strZonePrior & "=" & strZoneID)
DoCmd.RunSQL "UPDATE TBL_Cells SET TBL_Cells.WineID = " & strWineID & ", TBL_Cells.DateIn = Date()" & _
"WHERE (((TBL_Cells.CellID)=" & strCellID & "));"
BtlCntIn = BtlCntIn - 1
Wend
[COLOR="SeaGreen"] ' Delete wine[/COLOR]
DoCmd.RunSQL "DELETE TBL_WineIn.WineID, TBL_WineIn.NumberBtls, TBL_WineIn.DateIn, TBL_WineIn.ZoneID, TBL_WineIn.BtlCnt " & _
"FROM TBL_WineIn " & _
"WHERE (((TBL_WineIn.WineID)= " & strWineID & "));"
WineCnt = WineCnt - 1
Wend
[COLOR="SeaGreen"]' Generate cell allocation report[/COLOR]
DoCmd.OpenReport "RPT_WineInToday", acViewNormal, , , acWindowNormal
End Sub