ClaraBarton
Registered User.
- Local time
- Today, 13:46
- Joined
- Oct 14, 2019
- Messages
- 680
@MajP posted this function for retrieving values from popup forms:
How would I go about retrieving 2 values from a popup?
The way I'm doing it now, it opens for popup twice and just seems messy.
Code:
Public Function getValueFromPopUp(formName As String, PopUpControlName As String, Optional MyOpenArgs As String = "None") As Variant
'FormName: Name of the popup form
'PopupControlName: Name of the control on the pop up/dialog that you want the value
'MyOpenArgs: If you want to pass something to your pop up.
Dim frm As Access.Form
Dim ctrl As Access.Control
'Code execution stops after next line of code
DoCmd.OpenForm formName, , , , acFormEdit, acDialog, MyOpenArgs
'Wait until form is closed or hidden
'The popup needs an OK button that hides the popup(me.visible = false), and a Cancel button that just closes it
If CurrentProject.AllForms(formName).IsLoaded Then
Set frm = Forms(formName)
Set ctrl = frm.Controls(PopUpControlName)
If ctrl.controlType = acLabel Then
getValueFromPopUp = frm.Controls(PopUpControlName).Caption
Else
getValueFromPopUp = frm.Controls(PopUpControlName).Value
End If
DoCmd.Close acForm, frm.Name
End If
End Function
Code:
dtstart = getValueFromPopUp("popDate", "begDate")
dtend = getValueFromPopUp("popDate", "endDate")