List form not linking to detail form (1 Viewer)

EHS

Registered User.
Local time
Yesterday, 17:32
Joined
Jun 23, 2011
Messages
22
Hi there
I have a form that lists people. Each field has a click event that opens a people detail form using docmd.openform "PeopleDetail", , ,"str(PeopleCode = " & str(Form!PeopleCode). The detail form opens but always displays the first people record. PeopleCode is an AutoNumber, hence the str(). All tables are linked. Can anyone help? I've used this technique in other forms and it works (even in the same database).
Thanks
 

EHS

Registered User.
Local time
Yesterday, 17:32
Joined
Jun 23, 2011
Messages
22
Thanks for that vbaInet. I tried "Str(PeopleCode) = '" & Str(Me.PeopleCode)", but I got the same result. If I don't use str() I get the error message 'Data type mismatch'.
 

vbaInet

AWF VIP
Local time
Today, 01:32
Joined
Jan 22, 2010
Messages
26,374
The correct syntax is clearly explained in the link provided. Note that it doesn't use Str() and it explains what to use to wrap your criteria if it is Text or Date. I would advise you re-read that link.
 

EHS

Registered User.
Local time
Yesterday, 17:32
Joined
Jun 23, 2011
Messages
22
Thanks again. I have read the link properly this time, and used 'DoCmd.OpenForm "People Details", , , "PeopleCode = " & Me.PeopleCode'. I didn't get the Data type mismatch error, but I didn't get the required record either. The record displayed was the (yet again) first record.
 

vbaInet

AWF VIP
Local time
Today, 01:32
Joined
Jan 22, 2010
Messages
26,374
If you open the form on its own, does it display ALL records?
 

EHS

Registered User.
Local time
Yesterday, 17:32
Joined
Jun 23, 2011
Messages
22
If I open the detail form on it's own, it does display all records.
 

vbaInet

AWF VIP
Local time
Today, 01:32
Joined
Jan 22, 2010
Messages
26,374
I really don't want to start downloading two db's. Can you consolidate them.
 

vbaInet

AWF VIP
Local time
Today, 01:32
Joined
Jan 22, 2010
Messages
26,374
Your main problem was you had code in the Open event which was "dirtying" your form. I also made some changes too.

See attached.
 

Attachments

  • TestPupilCode.accdb
    388 KB · Views: 60

EHS

Registered User.
Local time
Yesterday, 17:32
Joined
Jun 23, 2011
Messages
22
Thank you very much. That has been a great help
 

Users who are viewing this thread

Top Bottom