-
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
-
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
-
There are always global variables
public gintTemp as integer
-
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
-
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.