How to do a DLOOKUP - ms-access

I am trying to do a DLOOKUP but not sure where I am going wrong.
I have a table header of the date, in my example: 04/04/16
I have a table called tblMasterLeagueAvailability
I have a textbox called text2 with the individuals name in it
=DLookUp("04/04/16","tblMasterLeagueAvailability","[Name] = [Text2] ")
The formula above is not working.
I want it to lookup the table header 04/04/16 in tblMasterLeagueAvailability and show the results for the persons name in text2
Thank you in advance

The textbox reference must be outside the string. Try something like
=DLookUp("04/04/16","tblMasterLeagueAvailability",
"[Name] = '" & Replace(Forms!myForm![Text2], "'", "''") & "'")
You need the single quotes ' for filtering text fields.
The Replace() is there to prevent an error when [Text2] contains a ' itself.
Note: a column name "04/04/16" indicates a problematic table design.

Related

MS-Access, DLookup won't work while bound to non-ID column

I'm dealing with a Dlookup malfunction, and I've tried everything I can think of with no success.
So I have a combobox that has the ID and grade name as columns. The ID is numerical while the grade name is a mixture of numbers, letters, and a dash. It's trying to pull a decimal from the table to display on the form. I have no problem doing this IF the ID column is bound as opposed to the grade name.
I currently have
=DLookUp("[AD Max]","Grades New","[ID] =" & [Combo24])
which works if the ID column is bound and stored in the table.
However, if the grade name (e.g. B130-2380) is bound, then the field blinks and says #error.
I've tried
=DLookUp("[AD Max]","Grades New","[ID] ='" & [Combo24] & "'")
with no success, and
=DLookUp("[AD Max]","Grades New","'[ID] =" & [Combo24] & "'")
doesn't work either.
Can someone figure out what I'm doing wrong and give me some suggestions? Thank you.

Getting data from query using Dlookup

I have a query named "TeacherDistributions" includes the following :
TeachertorName Subject Class
and I use the code below to retrieve the teacher name according to value of two text boxes. However, it retrieves no teacher name. Am I mistaken in my code please ?
=DLookUp("[TeachertorName]","[TeacherDistributions]","[Subject]='" &
[txtSubject] & "' AND [Class]='" & [txtClass] & "'")
The code is correct, so either you feed the wrong values as parameters or a record for those parameters doesn't exist.

MS Access - Automatically calculate & display the value to textbox based on selection of two comboboxes

I'm new to Access, just try to build a database for input orders,
I would like to make a form to input orders with some auto calculation,
it seems easy, but I fail to make it, pls help! XP
Just want to auto calculate the commission in frmOrder by searching the related "CommRate" (based on "SalesID" & "ProductID") x "Quantity" and return value to commission field.
My file
I think you want to use dLookup for this. Something like:
MyVar = dLookup("CommRate", "tblComm", "SalesID = '" & Me.txtSalesID & "' and
ProductID = '" & Me.txtProductID & "'")
txtCommission.Value = MyVar * txtQuantity.Value
You'll have to change all the textbox names and field names and such to what you've actually got on your form and table, but that's the general idea.

#ERROR on =IIf(DCount [...] with Alphanumeric field

I am using a DCOUNT function to look at a table in access and see if a record exists - if it does then return a yes value.
=IIf(DCount("*","COMMENTS","[PROJECTID] = " & [PROJECTID])>0,"YES","")
This works great if my ProjectID is all numeric values - I only get #Error on the alphanumeric values.
I know that I have to make the ProjectID criteria a string but am having trouble placing the quotes.
First, break out the DCount piece and work on that by itself.
It sounds like your COMMENTS.PROJECTID field is text datatype, so add quotes before and after the value you concatenate into the third DCount argument (Criteria):
DCount("*", "COMMENTS", "[PROJECTID] = '" & [PROJECTID] & "'")
After you have that piece working correctly, add it into your IIf() function.

Displaying a record in a report when selecting the record ID in a combo box

I have almost finished a project and I would like some user options in the form.
I would like to allow the user to select a product code and when selected, it will find the relative record in the table and then display all the information from that in a report.
Any ideas on the best approach to this would help me out massively.
Use the combo box selection with DoCmd.OpenReport as the WhereCondition option.
So if the report's record source table or query includes a numeric field named product_code and your combo box is named cboProductCode ...
DoCmd.OpenReport "YourReport", _
WhereCondition:="[product_code] = " & Me.cboProductCode
If the field is text rather than numeric, add quotes around the value in the WhereCondition.
WhereCondition:="[product_code] = '" & Me.cboProductCode & "'"