<re******@bigfo ot.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Justin,
I see what you are trying to do. I tried something similar. Did you
try it? Does it work for you?
I tried this but since the box is opened modally (acDialog), the
function stopped executing on that statement until the dialog closed.
Then the function resumed execution at "IsFormLoaded(. ..)" but was too
late to grab the return value because the form was gone..
I've hacked it by storing the parameters in global variables inside a
code module. Its awfully ugly but I guess it works. Yuck!
Dean
repost - as it still hasn't appeared on my news server:
I did double-check it before I posted it. There is no need for global
variables. I guess you didn't put the code in for the two buttons as
described. There two buttons on the form cmdOK and cmdCancel should do
different things. The cancel button closes the form, so the value is lost
and the function returns an empty string. The OK button sets the form's
visible to false, so the function continues, the value is picked up from the
textbox before the form is actually closed.
Can you double-check what you did? I don't think I made a mistake - but it
has been known in the past!
' *************** *************** *************** *********
' Code for the form
Option Compare Database
Option Explicit
Private Sub cmdCancel_Click ()
On Error GoTo Err_Handler
DoCmd.Close
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub
Private Sub cmdOK_Click()
On Error GoTo Err_Handler
Me.Visible = False
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub
Private Sub Form_Open(Cance l As Integer)
On Error GoTo Err_Handler
Dim strOpenArgs As String
Dim astrValues() As String
Dim strValue As String
Dim lngPosition As Long
Dim lngCount As Long
Cancel = True
strOpenArgs = Nz(Me.OpenArgs, "")
If Len(strOpenArgs ) > 0 Then
astrValues = Split(strOpenAr gs, "|")
For lngCount = 0 To UBound(astrValu es())
strValue = astrValues(lngC ount)
lngPosition = InStr(strValue, "=")
If lngPosition > 1 Then
Select Case UCase(Left$(str Value, lngPosition))
Case "PROMPT="
Me.lblPrompt.Ca ption = Trim(Mid$(strVa lue, lngPosition + 1))
Case "TITLE="
Me.Caption = Trim(Mid$(strVa lue, lngPosition + 1))
Case "DEFAULT="
Me.txtResponse = Trim(Mid$(strVa lue, lngPosition + 1))
End Select
End If
Next lngCount
End If
If lngCount = 3 Then
' The right number of parameters have been passed
Cancel = False
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub
' *************** *************** *************** *********
' *************** *************** *************** *********
' Code in a separate module
Option Compare Database
Option Explicit
Public Function MyInputBox(strP rompt As String, _
strTitle As String, _
strDefault As String) As String
On Error GoTo Err_Handler
Dim strReturn As String
Dim strOpenArgs As String
strOpenArgs = "Prompt=" & strPrompt & "|" & _
"Title=" & strTitle & "|" & _
"Default=" & strDefault
DoCmd.OpenForm "frmMyInputBox" , , , , , acDialog, strOpenArgs
If IsFormLoaded("f rmMyInputBox") Then
strReturn = Nz(Forms!frmMyI nputBox.txtResp onse, "")
DoCmd.Close acForm, "frmMyInput Box"
End If
MyInputBox = strReturn
Exit_Handler:
Exit Function
Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Function
Private Function IsFormLoaded(st rName As String)
IsFormLoaded = (SysCmd(acSysCm dGetObjectState , acForm, strName) <> 0)
End Function
' *************** *************** *************** *********