Results 1 to 3 of 3

Thread: Pass String(s) between Forms

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Atlanta, GA
    Posts
    80

    Question

    What is the best way to pass a string from one form to another? I have multiple instances of a main form which allows a user to select multiple users for a query.

    For layout purposes... Rather than putting the user listbox on the main form, I have a Select User (frmSelUser) form opened with the user listbox.

    I would like to pass the calling formname to frmSelUser so that I know which form to pass the string of selected users back to... since there can be multiple instances of the form opened at one point in time.

    Thanks!
    Kevin
    VB6 w/SP4

  2. #2
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810

    Wink

    If the form has a module level variable, then this can be assigned from another form, provided that it is loaded,

    See the following example:

    Create a new project,

    Add two forms, with a command button on each and a bas module,

    In the declarations of Form1 paste the following:

    Option Explicit

    Private Sub Command1_Click()
    ReDim Preserve NewFrm(intNo)
    Set NewFrm(intNo) = New Form2
    Load NewFrm(intNo)
    NewFrm(intNo).Caption = "Form" & intNo
    NewFrm(intNo).Myvar = "Form" & intNo
    NewFrm(intNo).Show
    intNo = intNo + 1
    End Sub

    In the declarations of Form2 paste the following:

    Option Explicit
    Public Myvar As String

    Private Sub Command1_Click()
    MsgBox Myvar
    End Sub

    In the declarations of Module1 paste the following:

    Option Explicit

    Public NewFrm() As Form

    Public intNo As Integer


    Press F5 when the command1 is clicked on Form1 a new form is drawn, and its Myvar is assigned a new value,

    Click the Command1 on the new forms will display a message from that variable.

    Hope this helps................ ;-)

    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Atlanta, GA
    Posts
    80
    Thanks! That helped!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width