Link to home
Start Free TrialLog in
Avatar of LillyC
LillyCFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Linking ID's from form to form using the 'where condition'

Hello

Can anyone tell me how to link an ID from one form to another using the 'where condition' within a macro in Access 2013.

I've tried it several times but can't get it to work.

Thanks
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

I think something is missing....when you say "where condition"..what kind of linking you want...
In the form/subform scenario the subform is filtered according to the Parent form link field/s
Avatar of LillyC

ASKER

I'm not trying to link from a form to a subform.

Its a 'client details form' to a 'job details form' and I'm trying to get the Client ID to feed through, I thought this had to be done via the 'where condition'?
can you give a screenshot...
try this code

if clientid is Number type, use this

docmd.openform "formX",,, "[clientid]= " & me.clientId


if clientid is Text type, use this

docmd.openform "formX",,, "[clientid]= '" & me.clientId & "'"


.
I think you need this
DoCmd.OpenForm "TheNameofForm", acNormal,,"ClientID = " & me.ClientID,,acDialog

Open in new window

Take a notice at the part "ClientID = " & me.ClientID which essentially is the WHERE condition but without the WHERE keyword...
If your criteria are alphanumeric then you change this to
"ClientID = '" & me.ClientID & "'"

Open in new window

Avatar of LillyC

ASKER

Is there any way I could do this within the macro rather than entering the code?
Your macro is failing probably because your criteria are alphanumeric...
you should have
Where Condition= [Client] = Chr(34) & [Forms]![YourForm]![ClientID] & Chr(34)
Avatar of LillyC

ASKER

The client ID is a Autonumber, its not alphanumeric...
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LillyC

ASKER

Thank you.
One thing the others left out is that if you add records with this popup form, you must populate the foreign key manually.  With a subform, the master/child links take care of linking the two records.  That isn't available in this case.  So - using the popup form's BeforeInsert event -

Me.FK = Forms!originalform!PK