|
 |
access thread: Returning values from a custom dialog
Message #1 by "Paul Moore" <pdmoore@g...> on Sat, 20 Apr 2002 15:06:24
|
|
Is there a way to get a closing form to return a single value in the same
way that the MsgBox does?
All the examples I find suggest setting a global variable, which is
useless to me as this dialog will need to be used repeatedly.
Any ideas?
Message #2 by braxis@b... on Sat, 20 Apr 2002 19:50:18
|
|
Paul
Here's a fairly elegant method, which will work so long as you can call
the form that's gathering the information in dialog mode.
So call the form with code like this:
Private Sub frmOpen_Click()
On Error GoTo Err_frmOpen_Click
Dim strReturn As String
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmDialog"
'Code stops here until the called form is hidden
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog
'Grab the result here
strReturn = Forms![frmDialog].ReturnValue
'Now close the form
DoCmd.Close acForm, "frmDialog"
Exit_frmOpen_Click:
Exit Sub
Err_frmOpen_Click:
MsgBox Err.Description
Resume Exit_frmOpen_Click
Here's the code for the dialog form:
'module level variable to hold the result
Dim mstrToReturn As String
Private Sub btnClose_Click()
On Error GoTo Err_btnClose_Click
'Calculate your result and make the form invisible
'code resumes in calling routine
mstrToReturn = Me.txtValue & " To return"
Me.Visible = False
Exit_btnClose_Click:
Exit Sub
Err_btnClose_Click:
MsgBox Err.Description
Resume Exit_btnClose_Click
End Sub
Public Property Get ReturnValue() As String
Return the value
ReturnValue = mstrToReturn
End Property
Hope this helps
Brian
> Is there a way to get a closing form to return a single value in the
same
w> ay that the MsgBox does?
> All the examples I find suggest setting a global variable, which is
u> seless to me as this dialog will need to be used repeatedly.
> Any ideas?
Message #3 by "Paul Moore" <pdmoore@g...> on Thu, 25 Apr 2002 04:13:27
|
|
Brian,
I just got back to this. It looks great!
Thanks,
Paul
|
|
 |