Please show the code behind these combos and for filling the St Code, OT code controls.
You may also get some info from this Allen Browne article.
Just to be clear...am I correct in assuming that the 'Job Title' comes from the 'Craft' Field in your Table?
Linq ;0)>
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007
Private Sub Company_AfterUpdate()Please show the code behind these combos and for filling the St Code, OT code controls.
You may also get some info from this Allen Browne article.
Me.STCode = DLookup("STCode", "tblcraft", "Company=" & Me.Company)
Me.OTCode = DLookup("OTCode", "tblcraft", "Company=" & Me.Company)
End Sub
No the "Job Title comes for "tblEmployeeDetails" its a different table
Should probably look more like this assuming I understand your relationships:
Some if the field/object names may not be right but to answer the subject title of the post: you can use multiple criteria in the dlookup function, the syntax would look just look the where clause in a SQL query. Eg "field1=123 AND field2='abc' OR field3<#12/25/2018#" so on and so forth...
Look at the string that you built for the cirteria:
Company=AYTB AND Job_Title=Lead
Because company and job_title are string fields the values need to be surrounded by quotation marks
Company="AYTB" AND Job_Title="Lead"
So your code would look like
However, is Job_Title = Me.Job_Title even correct? From the original post tblCraft's field name is Craft, not Job_Title. I would expect it to look more like this:Code:Me.STCode = DLookup("STCode", "tblcraft", "Company=""" & Me.Company & """ AND Job_Title=""" & Me.Job_Title & """")
Code:Me.STCode = DLookup("STCode", "tblcraft", "Company=""" & Me.Company & """ AND Craft=""" & Me.Job_Title & """")
Prefect thank you soo much it's working....Look at the string that you built for the cirteria:
Company=AYTB AND Job_Title=Lead
Because company and job_title are string fields the values need to be surrounded by quotation marks
Company="AYTB" AND Job_Title="Lead"
So your code would look like
However, is Job_Title = Me.Job_Title even correct? From the original post tblCraft's field name is Craft, not Job_Title. I would expect it to look more like this:Code:Me.STCode = DLookup("STCode", "tblcraft", "Company=""" & Me.Company & """ AND Job_Title=""" & Me.Job_Title & """")
Code:Me.STCode = DLookup("STCode", "tblcraft", "Company=""" & Me.Company & """ AND Craft=""" & Me.Job_Title & """")
As you said this code was right " Me.STCode = DLookup("STCode", "tblcraft", "Company=""" & Me.Company & """ AND Craft=""" & Me.Job_Title & """")"
You can use an apostrophe instead of the two quote marks.
Me.STCode = DLookup("STCode", "tblcraft", "Company='" & Me.Company & "' AND Craft='" & Me.Job_Title & "'")"
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.