PDA

View Full Version : Passing parameters between forms.



cath_hopes
10-15-2007, 04:04 AM
Hello again!
I am trying to pass parameters between two forms. The second form opens but not at the record I want because the parameter (Primary key) doesn't seem to be picked up by the second form.
The code from Form1 is:
Dim Num As Integer
Num = Combo17.Value
DoCmd.OpenForm "Property Form", , , "Property.[Property ID] = " & Num
Property Id is the primary key of the second form (Property). Num contains the value of the Property ID selected from combo 17 in Form1.
The second form opens with none of its Property fields populated.

I'd really appreciate some help with this as I've going round in circles for some time now!!

Thanks heaps in advance,
Catherine

OBP
10-15-2007, 05:04 AM
Catherine, have you checked what value is being held in the variable "Num"?
I am not sure that Combo17.value is the best way to transfer the selection.
You might be better off using Combo17.Column(0).
More to the point why not get the Command Button Wizard to do it for you?

akn112
10-15-2007, 05:44 AM
Hey there, for passing more than one variable, there's two ways i do it (not sure if they're the best though). One was is through the openargs:




DoCmd.OpenForm "frm2", , , , , , "Parameter1;Parameter2"

on form2:

Dim Arguments As Variant
Arguments = Split(Me.OpenArgs, ";")

so

arguments(0) = parameter1
arguments(1) = parameter2



the second way i sometimes use if i'm displaying the parameters on the form. So for say form2 i have a txt1 and txt2, and form1 i have cbo1, u can just use direct reference in ur form_load:



private sub form_load
txt2.value = Forms!frm1!cbo1.Value
txt1.value = Forms!frm1!cbo2.Value
end sub


and of course ull want to add in proper null handling for both cases.

HTH

cath_hopes
10-15-2007, 02:36 PM
Hi OBP,

I've tried both your suggestions:
I found that combo17.column(0) works fine - Thanks for that.
I tried setting up the command button with the wizard but had a few issues with it:
1) There were no form1 fields to match with the form2 fields of the openform for form2 which is especially odd since they use the same table or is this the reason?
2) the wizard didn't offer an ascending / descending option within each column
3) one a user selects/clicks on a row only the first column is returned which doesn't look aesthetic.