I am able to get the result I'm looking for if I run a query with the
following select statement, but I can't get it to appear in a text box on a
form:
SELECT TOP 1 tblSHistory.SiteNum
FROM tblSHistory
WHERE (((tblSHistory.EmpNum)=388288))
ORDER BY tblSHistory.StartDate DESC;
388288 is an employee number I used. Somehow I need to replace it with
me.empnum, or forms!frmFSRInfo!empnum.
Jonathan Brown said:
Here's how i've got it setup:
tblEmployees
------------------------
EmpNum, Autonumber, PK
Name, Text
...
tblSites
---------------------
SiteNum, autonumber, PK
SiteName, text
...
tblSHistory
-----------------
SHistoryNum, autonumber, PK
SiteNum, FK to tblSites
EmpNum, FK to tblEmployees
StartDate
Thanks for your help.
Just a text box that displays the employee's current site name being that
it'd be the last record or record with the most current startdate in the site
history table for a given employee.
Klatuu said:
I am going to have to set up a test situation and see what it needs. I'll
get back to you later today.
--
Dave Hargis, Microsoft Access MVP
:
When I put an equal sign I get a syntax error: "The syntax of the subquery in
this expression is incorrect. Check the subquery's syntax and enclose the
subquery in parentheses."
If I include the equal sign and then enclose the rest of it in parentheses I
the #name? error message again.
:
No, but you do need an = sign in front of it.
--
Dave Hargis, Microsoft Access MVP
:
I'm still getting the #Name? error message. However, I just selected your
text and pasted it and changed the form name to match my form name. In the
control boxes' control sources don't we have to add some extra ()'s? or []'s?
All the SQL select queries seem to be formatted differently if it's for a
query, a control source, row source or in code.
:
Select tblshistory.sitename
From tblShistory
Where tblShistory.startdate = Dmax("startdate", "tblSHistory", "empnum = " &
Forms!MyFormName!empnum )
Note: Queries do not understand Me. You have to fullly qualify the control
as shown above.
--
Dave Hargis, Microsoft Access MVP
:
I have an employees table and a sitehistory table. 1 to many relationship.
One employee may have been assigned to more than one site historically.
I want to place a textbox on a form that displays the site that the employee
is currently assigned to.
I'm thinking that the select statement should look something like:
Select tblshistory.sitename
From tblShistory
Where tblshistory.empnum = me.empnum AND Dmax("startdate")
But that doesn't seem to work I keep getting a #Name error.
Can anyone help me out?