Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call A Form Like a Function 2

Status
Not open for further replies.

VictoryHighway

Technical User
Mar 4, 2004
115
US
Hello,
I would like to know if I can "call" a form like I would a function and have the form return a value.

What I'm looking to do is to pop up a small form with a list of files, wait for the user to select a file and return the filename when the user clicks OK.

I've already figured out how to use the FileList control to get my list of files. But, all I need to know now is how can I get that filename back into the original procedure?

Any help would be appreciated.

Thanks,
Geoffrey
 
I do this all the time with my apps.

1. Create a form
2. Add a sub that accepts parameters (some byval and some byref)
3. In that subroutine, call Show(Modal)

Here's an example of a form with a text box, an OK button and a Cancel button.

Code:
Option Explicit

Dim bCancel As Boolean
Dim cEditText As String

Public Sub GetSingleEdit(ByVal Caption As String, ByVal MaxLength As Long, ByRef EditText As String, ByRef Cancel As Boolean)
    
    Me.Caption = Caption
    txtEdit.MaxLength = MaxLength
    txtEdit.Text = EditText
    txtEdit.SelStart = 0
    txtEdit.SelLength = Len(txtEdit.Text)
    bCancel = True
    
    Call Show(vbModal)
    
    Cancel = bCancel
    EditText = cEditText
    
End Sub


Private Sub btnCancel_Click()
    
    Unload Me
    
End Sub

Private Sub btnOK_Click()
    
    bCancel = False
    cEditText = txtEdit.Text
    
    Unload Me

End Sub



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Oh, and to use it...

Dim strName as String
Dim bCancel as Boolean

Call frmSingleEdit.GetSingleEdit("Enter Your Name", 50, strName, bCancel)
If bCancel Then
' The user Canceled
Else
Msgbox "Hello " & strName
End If

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
George,
Thanks very much! That works perfectly! That will be very useful!

--Geoffrey
 
Glad to help and thanks for the star.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top