MS Access Dlookup #Error or ?Name value - ms-access

I've got a foreign key lookup in the form of the following two tables -
tblApplications
applicationId
applicationName
tblApplicationsManagement
application (references tblApplications.applicationId)
I have a text field on a form that is setup with tblApplicationsManagement which I want to reference the applicationName through the relationship.
I've tried this -
=DLookup("[applicationName]", "tblApplications","[applicationId] = [tblApplicationsManagement]![application]")
And all I get is #Error on the initial Form entry and everything comes up blank.
edit - the following returns #Name? on all entries
=DLookUp("[applicationName]","tblApplications","application=" & [applicationId])
To make sure I'm capturing all the right info. I'm trying to populate a Plain Text field with the [applicationName] from the foreign key. the Text Field name is fieldApplicationName
NOTE for any viewers - The solution is correct. The issue was on the SQL side having a column called "application" which isn't specified as a keyword but it must be somewhere either on the SQL or MS Access side.

If your form includes a text box named txtApplication which is bound to the tblApplicationsManagement.application field in your form's Record Source, this should work as the Control Source for the problem text box ...
=DLookup("[applicationName]", "tblApplications", "[applicationId] = " & [txtApplication])
Note I presumed tblApplicationsManagement.application and tblApplications.applicationId are both numeric datatypes. If they're text, you'll need to add quotes ...
=DLookup("[applicationName]", "tblApplications", "[applicationId] = '" & [txtApplication] & "'")

Related

MS ACCESS formatNumber in Calculated Field

I have a uID field linked to an auto number field Num that generates unique, custom numbering for each record in a table.
However the Expression used for the Data type keeps returning an error.
If Field1 = "Cat" then field (uID) must return "C" & [Num]. With the number format "000". ie C001, C010, C121 etc
IIf([Field1]="Cat","C" & formatNumber([Num],3) & [Num],"Unknown")
It seems Access doesn't recognise formatNumber used in this manner.
put this code in your textbox control source
=IIf([Field1]="Cat";"C"+Format([NUM];"000");Null)
this will give you the output what you need.

How to use the DLookUp function and if it is the correct function for this job?

I have two tables in my database, and a form that is opened when the user logs in.
A text box in this form will display that users name e.g. "Ollie", I want another text box to display this users contracted hours from within the users table when the form is opened.
I have tried using the DLookUp form in the before update section however nothing happens? Below is an example of what I have tried.
=DLookUp("[ContractedHours]","tblUser","[Operator] =[tblUser]![UserLogin]")
So saying that the value in my form text box "Operator" is Ollie, the value in my table column "UserLogin" is Ollie, i'd like another text box on the form to display the contracted hours on the record for Ollie.
tblUser contains these columns
ID UserLogin Contracted Hours Password
1 Ollie 8:00 *****
2 Ryan 5:00 *****
My form contains a text box that will equal either Ollie or Ryan, and I would like another text box that displays the relevant Contracted Hours.
DLookup will only work if you provide it a valid condition that allows it to identify a specific record in the table. What you have provided is not a value; it's a reference to a column in a table. There's no way for DLookup to know which record you are referring to.
Have a look at this page for some working examples. Notice they all have a condition that points to a specific record:
DLookup("UnitPrice * Quantity", "Order Details", "OrderID = 10248")
or
DLookup("CustomerID", "Orders", "OrderID = Forms![Orders]!OrderID")
It should read like:
=DLookUp("[ContractedHours]","tblUser","[UserLogin] = '" & Me!TextboxWithUserName & "'")
Based on your excerpt from table users, it's probably because you didn't include the space in the Contracted Hours column name in your DLookUp. Also, I would put your form call outside of the string.
Try:
=DLookUp("[Contracted Hours]","tblUser","[Operator] = '" & Forms![tblUser]![UserLogin] & "'")

ACCESS form expression builder

I am trying to display a record from a table after the user enters the input. I have several tables but the one from which I am trying to take the data is called Tocki. Till now I came up with this expxression:
=DLookUp("[Tocki]![Y]"," [Tocki]![X]"," [Tocki]![H]";" [Tocki]![Broj]="&[Text3])
I want to display the columns Y, X and H from the table Tocki. My text field is called Text3 and I want to search the table through the column Broj.
Did you mean a textbox is named Text3?
Cannot pull 3 separate fields with DLookup, you can pull a concatenation of those three fields. If Broj is a text type field, filter parameter needs apostrophe delimiters.
=DLookUp("[Y] & ':' & [X] & ':' & [H]", "Tocki", "[Broj]='" & [Text3] & "'")
However, DLookup can be slow performer. Better approaches usually:
include lookup table in the form RecordSource, bind textboxes and set them Locked Yes and TabStop No
multi-column combobox, then textboxes can reference the combobox columns by index

MS Access - Dlookup criteria from selected item (listbox)

I've seen similar questions but the provided answers couldn't solve my problem.
In access I created a form.
From a listbox you can select a name. The names are listed in the table tNames in the column names_combined (last name, given name) . In two other columns last name and given name are separated.
On the right side of the listbox you can find information about the name which will be shown in text boxes.
The goal is to show the last name from table tNames.lastname by looking for tNames.names_combined.
So I tried this:
=Dlookup("lastname";"tNames";"names_compined =" & Me.listbox)
However I just get error messages in my text box.
Thanks in advance!
DLookup requires commas not colons.
This should work assuming all the names of tables/fileds and controls are correct:
=Dlookup("lastname","tNames","names_compined='" & Me.listbox & "'")
Also make sure the actual bound field of your listbox is the combined name (by the way you code says comPined).
Finally as it was pointed out in the other answer me.something will only work in the form itself or its VBA module. Everywhere else you need a global identifier.
Try with:
=Dlookup("lastname";"tNames";"names_combined = '" & Forms!YourForm!listbox & "'")

Access Expression using a combo box to complete a text box

The expression:
=IIf(([cbo1]IS NOT NULL),DLookUp("[Thing1]","[tbl1]","[cbo1]= " & [Forms]![frm1]![cbo1]), "")
returns "#Error" when I try to use it to populate a text box based on the value of a combo box. The values in the combo box are all words, so setting
=IIF([cbo1]>0
in the first part creates a different error. I have this expression on a different part of the form and it works fine for numerical values.
=IIf(([txt1]>0),DLookUp("[thing1]","[tbl11]","[Thing2]= " & [Forms]![Frm1]![txt1]),"")
What am I missing on the one dealing with text?
IS NOT NULL is supported in Access SQL, but not in VBA expressions. Use IsNull().
=IIf(Not IsNull([cbo1]), DLookUp("[Thing1]", "tbl1", "[cbo1]=" & [cbo1]), "")
Note the DLookUp expression requires that tbl1 includes a numeric field named cbo1, the same as your combo box name. That could be correct, but it looks suspicious to me. Double-check that field name if you get another error.