Re: Passing a value from one form to another
From: Björn Holmgren (bjohol_at_hotmail.com)
Date: 11/22/04
- Next message: Larry Serflaten: "Re: For each loop through a Collection of Activex Exe"
- Previous message: Starbuck: "VB6 and MS Word Question"
- In reply to: Macsicarr: "Passing a value from one form to another"
- Next in thread: Macsicarr: "Re: Passing a value from one form to another"
- Reply: Macsicarr: "Re: Passing a value from one form to another"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 22 Nov 2004 11:58:34 +0100
"Macsicarr" <news@DoNotEmailMe.co.uk> wrote in message
news:OTCrrTB0EHA.1564@TK2MSFTNGP09.phx.gbl...
> Hi All
>
> As per usual I'm starting a major hobby project (for me anyway) before I
can
> VB walk!
>
> Although what I have done works, I'm sure it is not the correct way so I
> thought I would ask the gurus.
>
> In concise terms, I have 2 forms. The first form has a control array of
say
> 10 labels and a control array of say 10 buttons. The captions on the
labels
> and the tags on the buttons are populated from an Access DB using ADO/SQL.
> This part of it works fine, please do not see this as a DB query.
>
> When the user clicks on the relevant button, I need to bring up my second
> form, hide my 1st form and populate the control array of labels on this
2nd
> form with other data from this Access DB. This Access DB data is derived
> from the ID that is stored in the relevant button's tag. Basically each
ID
> queries the data for the row that has this ID. This part works fine and
> again is not my query.
>
> My query is that at present, I hide the first form, show the 2nd form, get
> the value from the button's tag, query the DB and populate the 2nd form
all
> from the onClick event in the 1st form. Although it works, I just feel
that
> I should be sending the ID from the 1st form to the 2nd form, the 2nd form
> does all of the populating and when the user clicks the back button on my
> 2nd form, this 2nd form is simply hidden and the 1st form is shown.
>
> I do a lot of ASP web programming and this latter submit then
> request/display logic ... well seems more logical than what I am currently
> using.
>
> Can you advise me on my pitfalls and solutions.
>
You're absolutely right that the 2nd form should populate its own controls
without being dependent on code in the 1st form. So the question is how does
the 2nd form know what ID to use?
Personally, I would prefer using a public property in the 2nd form. When the
property is set, the code in the Property Let procedure populates the
controls. Here'a a small example (air code).
Form 1:
Private Sub Command1_Click(Index As Integer)
' Pass the ID to form2 using public property
Form2.ID = Command1(Index).Tag
' Now show the form (modal)
Form2.Show vbModal, Me
' Execution continues when form2 is unloaded or hidden
End Sub
Form 2:
Public Property Let ID(newID As String)
' Form is automatically loaded when this property is set
' TODO: Populate form using the value of "newID"
End Property
-- Björn Holmgren
- Next message: Larry Serflaten: "Re: For each loop through a Collection of Activex Exe"
- Previous message: Starbuck: "VB6 and MS Word Question"
- In reply to: Macsicarr: "Passing a value from one form to another"
- Next in thread: Macsicarr: "Re: Passing a value from one form to another"
- Reply: Macsicarr: "Re: Passing a value from one form to another"
- Messages sorted by: [ date ] [ thread ]