HELP! FORMS AND SUBFORMS

  • Thread starter Thread starter Ioia
  • Start date Start date
I

Ioia

MAIN FORM: CLIENTSDETAILSTAKEN---PRIMARY KEY: CLIENT ID
RELATIONSHIP: ONE TO MANY
SECONDARYFORM: ENQUIRIES
FOREIGNKEY: CLIENT ID
In the first form, there is a button (Form control) in order to open the
form Enquiries. I would like that every time I click on the button; the
CLIENTID field from ENQUIRIES was populated automatically with the CLIENTID
of the Form CLIENTSDETAILSTAKEN that I’m working. As it would do it if I had
the subfom in the main form.
Any help would be much appreciate it
Thanks
Ioia
 
Iola -

The OpenForm command lets you pass in criteria you want met. In your case
it might look like this (substitute ClientID in Me.ClientID with the control
name on your main form that has the ClientID in it.

DoCmd.OpenForm "Enquiries", , ,"CLIENTID = '" & Me.ClientID & "'"
 
MAIN FORM: CLIENTSDETAILSTAKEN---PRIMARY KEY: CLIENT ID
RELATIONSHIP: ONE TO MANY
SECONDARYFORM: ENQUIRIES
FOREIGNKEY: CLIENT ID
In the first form, there is a button (Form control) in order to open the
form Enquiries. I would like that every time I click on the button; the
CLIENTID field from ENQUIRIES was populated automatically with the CLIENTID
of the Form CLIENTSDETAILSTAKEN that I’m working. As it would do it if I had
the subfom in the main form.
Any help would be much appreciate it
Thanks
Ioia

What's wrong with using a Subform? If you're short of screen space, consider
using a Tab Control, with the subform on one page and other controls on
another.

If you have some good reason to pop up a separate form, you need some code. In
the command button, pass the clientID in *both* the OpenForm's WhereCondition
argument (to limit the popped up form to the desired client), *and* in its
OpenArgs:

DoCmd.OpenForm "Enquiries", WhereCondition:="[Client ID]=" & Me![Client ID], _
OpenArgs:=Me![Client ID]

Then on the Open event of the Enquiries form, use the OpenArgs to set the
default value:

Private Sub Form_Open(Cancel as Integer)
If Me.OpenArgs & "" <> "" Then
Me.[Client ID].DefaultValue = """" & Me.OpenArgs & """"
End If
End Sub

The default value property must be a string, whatever the datatype of the
field, hence the quotemarks.
 
Thank you John! Sometimes the simplest solution is the best. I used a Tab
Control one page the main form and the second the subform. It works perfectly.
Many Thanks
John W. Vinson said:
MAIN FORM: CLIENTSDETAILSTAKEN---PRIMARY KEY: CLIENT ID
RELATIONSHIP: ONE TO MANY
SECONDARYFORM: ENQUIRIES
FOREIGNKEY: CLIENT ID
In the first form, there is a button (Form control) in order to open the
form Enquiries. I would like that every time I click on the button; the
CLIENTID field from ENQUIRIES was populated automatically with the CLIENTID
of the Form CLIENTSDETAILSTAKEN that I’m working. As it would do it if I had
the subfom in the main form.
Any help would be much appreciate it
Thanks
Ioia

What's wrong with using a Subform? If you're short of screen space, consider
using a Tab Control, with the subform on one page and other controls on
another.

If you have some good reason to pop up a separate form, you need some code. In
the command button, pass the clientID in *both* the OpenForm's WhereCondition
argument (to limit the popped up form to the desired client), *and* in its
OpenArgs:

DoCmd.OpenForm "Enquiries", WhereCondition:="[Client ID]=" & Me![Client ID], _
OpenArgs:=Me![Client ID]

Then on the Open event of the Enquiries form, use the OpenArgs to set the
default value:

Private Sub Form_Open(Cancel as Integer)
If Me.OpenArgs & "" <> "" Then
Me.[Client ID].DefaultValue = """" & Me.OpenArgs & """"
End If
End Sub

The default value property must be a string, whatever the datatype of the
field, hence the quotemarks.
 
Back
Top