Function DLookup in Ms Access 2016 - ms-access

gives me
when saving records in the system.
Can anyone let me know what is the problem in this?
xx = DLookup("[part_number]", "tblModelCost", "[Customer_ID]= " & me.Customer_ID & " and [Model] = '" & me.[txtModel] & "' and [Description] = 'screen'")

Looks like Me.Customer_Id should be Me!Customer_Id. However, that depends on the form control name and what you are trying to do. Assuming you have a control named "Customer_ID" and a field named "Customer_ID" Me.Customer_ID will try to use the the control value, me!Customer_ID will try to use the underlying bound field value. If you don't have a control named Customer_ID then using Me.Customer_ID will cause the error you are getting. (This is why you want to learn to use controls names like txtCustomer_ID for your controls. )

Related

Open Form to specific record

I'm struggling with a code I found on Stackoverflow. It keeps on telling me:
run-time error "424: object required".
I want to double-click on a record within a list box to open a form to the specific record clicked. The value from the record that I need the form to navigate to is found in Column 1 of the list box.
List Box Name: frmDashboardJBCreate
Field name in the table: JobcardNumber (numeric field)
Form Name: frmJobcardCreate
Table Name: tabJobcard_Issue
The code I tried is the following; but it keeps on giving me the error mentioned above:
DoCmd.OpenForm "frmJobcardIssue", , , _
"[JobcardNumber] = '" & Me.frmDashboardJBCreate.Column(1).Value & "'"
Could you please assist me?
If JobcardNumber is numeric, don't use single quotes around the parameter.
ListBox.Column() is zero-based, so if you want the first column, it's
DoCmd.OpenForm "frmJobcardIssue", , , _
"[JobcardNumber] = " & Me.frmDashboardJBCreate.Column(0).Value
Note: frm usually stands for "Form", so it is rather confusing if you name a listbox frmDashboardJBCreate. Are you sure you have that name right?

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.

How to refer to field name dynamically using a variable in MS Access VB

I'm making a search form for keyword searches. I have comboboxes with values ["And","Or","Not"], comboboxes with a list of field names, e.g. ["Title","Description",...] and textboxes associated with each combobox. I'm trying to create the sql query based on the values of the comboboxes and text box. To do that, I need to refer to the field name based on the value of the combobox. I'm trying solutions I've found searching, but I'm still getting the error: "Compile error: Sub or Function not defined". The debugger highlights "VHS_Metadata_Aug52014(field)" in yellow.
.....
bool_type = Me!Controls!dropBoolType2.value
field = Me!Controls!dropSearch2.value
value = Me!Controls!txtKeywords2.value
If (value) > 0 Then
SQL_query_string = SQL_query_string & " " & bool_type & " " & VHS_Metadata_Aug52014(field) = " & value"
End If
.....
I'd use dot notation instead. Using bangs like that doesn't let you use variables very easily. Try something like
Forms("formname").controls(foo).value
Where foo is the value from the combobox.
I'm not sure what VHS_Metadata_Aug52014 is though, if it's the name of the form you were trying to reference, you were partly there.

Microsoft Access "if" statement

A very specific question - wondering if someone would simply be able to put together the code for me! I have no experience with code... at all.
I have a table consisting completely of associate information (Name, Phone, ID, Position, etc). I'm building a report on which I only want the Name to display, but ONLY IF their Position = "Tech"
I've come to find this formula for displaying their names in the "last name, first name" format:
=[LastName] & ", " & [FirstName]
but as I said... I only want this script to run if they're a "Tech" how would I write out the "IF" statement to make this work?
The best place for that would be in the query - add "WHERE Position = 'Tech'". Assuming you only want Techs to show up on the report.
If you want everyone to show up but only want names to be visible for techs, you can use an IIf statement: = IIf(Position = "Tech", [LastName] & ", " & [FirstName], "")
That will show the name for a tech, or a blank for anyone else.

MS Access Syntax error

here is my code:
Text22 = DLookup("[Program_No]", "1_Supportive_Housing", "[Program_Name] = '" & Replace([Me.Program_Name], "'", "''") & "' And [BudgetYear] = " & [Me.BudgetYear])
I am not sure what is wrong with it, but it keeps giving me the following error:
Can't find the field | in your expression
I have been trying to get rid of this error but nothing works.
OnKeyPress, this event triggers. As the user writes, it should be able to lookup the value in the table and assign it to text22.
Looks like you want to reference to form fields [Me.Program_Name] & [Me.BudgetYear], but Access tries to find fields with exactly this name, including "Me." prefix. Try to remove brackets at all, or use Me.[Program_Name] and Me.[BudgetYear] instead.