Code:
If TotalLiters > 31 Then
You have delcared "TotalLiters" as a STRING, but the statement above is comparing a string to a number.
"TotalLiters" is a string , 31 is a number.
31 (no quotes - a number) is different than "31" (with quotes - a string)
Code:
TotalLiters = "Select LitersNeeded From [tblMediaList] WHERE [Select Media] = true"
You cannot set a variable equal to a SQL statement and have a value returned.
You can open a recordset
Code:
Option Compare Database
Option Explicit
Private Sub Check24_AfterUpdate()
Dim TotalLiters As String
Dim rs as DAO.Recordset
Set rs = Currentdb.Openrecordset("Select LitersNeeded From [tblMediaList] WHERE [Select Media] = true")
'There would only be one line in the table where Select Media =True'
If not rs.BOF and not rs.EOF Then
TotalLiters = rs!LitersNeeded
End If
'DoCmd.RefreshRecord
DoCmd.OpenQuery "qryCalculateIngredientsToAddAppendTable"
If TotalLiters > 31 Then
DoCmd.OpenQuery "qryCalculateIngredientsToAddAppendTable"
Else
DoCmd.OpenReport "RptCheckListforDaveChooseFromMediaList", acViewReport
End If
End Sub
or you could use DLookup()
Code:
Option Compare Database
Option Explicit
Private Sub Check24_AfterUpdate()
Dim TotalLiters As String
TotalLiters = DLookup("LitersNeeded","tblMediaList", "[Select Media] = true")
'There would only be one line in the table where Select Media =True'
DoCmd.RefreshRecord
DoCmd.OpenQuery "qryCalculateIngredientsToAddAppendTable"
If TotalLiters > 31 Then
DoCmd.OpenQuery "qryCalculateIngredientsToAddAppendTable"
Else
DoCmd.OpenReport "RptCheckListforDaveChooseFromMediaList", acViewReport
End If
End Sub