Results 1 to 5 of 5

Thread: Passing Values to Forms

  1. #1
    Adept Developer
    Guest

    Passing Values to Forms

    Maybe I'm still stuck in the 'web environment' but how do you pass a value to a form? For instance, my main form has a listview on it that is populated via database. I wrote some ItemClick and DblClick code to open a new form using frmName.Show vbModal.

    However, I want the primary key to be passed as a value to that form so that I can run a select statement based on that value.

    Can anyone help?

    -Steve

  2. #2
    Megatron
    Guest
    Why not just make use of the Tag property of the Form?
    Code:
    Form1.Tag = "MyValue"
    Form1.Show
    
    ' In Form1_Load event:
    Private Sub Form_Load()
        MsgBox Me.Tag
    End Sub

  3. #3
    Member
    Join Date
    Mar 2001
    Location
    pa
    Posts
    58
    There are always global variables

    public gintTemp as integer
    DAvid Rainey

  4. #4
    Adept Developer
    Guest
    I'm not familiar with the tag property, but I'll check it out. I don't want to use global variables for anything that shouldn't actually be globally accessable.



    I'm fairly new to VB, but I've been programming for years, so it's mostly learning new commands and maybe a little bit of windows theory.

    -Steve

  5. #5
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982

    Thumbs up

    I would say the best way to pass a value to a form is to give the form a property.
    Code:
    Public Property Let key(ByVal vNewValue As Variant)
       ' do something with the value before assigning etc.
       Value =vNewValue
    End Property
    For this you will need to dim a variable called on the same form
    Code:
    dim Value as variant
    obviously you will choose an appropriate data type. There is nothing wrong with the Tag property I just think this is tidier and gives you more control as you can do what you want in the property before assigning the value.
    For help on syntax use 'Add Procedure' from the Tools menu.


    Things I do when I am bored: DotNetable

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