Just in code. The variable "MaxSelected" gets compared to "CurrentSelected" on the after update of a button on the subform. Once CurrentSelected > MaxSelected, I have an error message pop up.
I'm new to using Public subs. I tried making the parent form's after event sub public, but I still couldn't call the variable.
This is the code that creates "MaxSelected":
Code:
Public Sub SlspSelect_AfterUpdate()
Dim MaxSelected As Integer
Me.NumSel.Requery
Me.F_DR_Select_Sub.Requery
Me.F_DR_Select_Sub.SetFocus
If IsNull(DLookup("AdjNumber", "T_SelectionNumAdj", "[Name] = '" & _
Forms!F_GalleySelections![SlspSelect] & "'")) Then
MaxSelected = 10
Else
MaxSelected = DLookup("AdjNumber", "T_SelectionNumAdj", "[Name] = '" & _
Forms!F_GalleySelections![SlspSelect] & "'")
End If
End Sub
Here is where I am trying to use it:
Code:
Private Sub Frame2_AfterUpdate()
Dim CurSelected As Integer
Dim msgTooMany As String
'Check to see how many names have been submitted.
msgTooMany = "You have selected the max amount. Add less people to the list " & _
"or send a mailer to less people."
CurSelected = DCount("Name", "T_DreamRooms", "[AddToList] = '1' AND [NoMail] = '1' " & _
"AND [Salesperson] = '" & Forms!F_GalleySelections![SlspSelect] & "'")
If CurSelected >= MaxSelected Then
MsgBox msgTooMany, vbOKOnly
Me.Frame2 = 2
Else
Select Case Me.Frame2
Case 1
[NextMailed] = Forms!F_GalleySelections!NextAdDate
Case 2
[NextMailed] = Null
End Select
DoCmd.RunCommand acCmdSaveRecord
Forms!F_GalleySelections.NumSel.Requery
End If
End Sub