MS Access Syntax error - ms-access

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.

Related

Access SQL error-message "database does not recognize as a valid field" - NOT Crosstab

I am receiving the following error: "The Microsoft Access database does not recognize '[ASX Code]' as a valid field name or expression."
Here is the code that throws the error:
QUICK_RATIO_CHART_SQL = "SELECT [Quick Ratio] FROM [RATIO ANALYSIS] WHERE [ASX Code] like '" & ASXCODE & "';"
Me.QUICK_RATIO_CHART.RowSource = QUICK_RATIO_CHART_SQL
'RATIO ANALYSIS' is a table that contains a field 'ASX Code'.
Can anyone point me in the right direction please?
Thanks
Lee
Not the answer, but a method to help you getting it right:
add debug.print QUICK_RATIO_CHART_SQL after the line QUICK_RATIO_CHART_SQL=...
run the proc until the debug.print is executed
paste the printed statement in a new view (in SQL view)
switch to design view and execute
you should then have a clear view of the error
That how I'd proceed when my eyes pop out my head, like it may happen sometimes.
You can also try to qualify everything, using an Alias:
QUICK_RATIO_CHART_SQL = "SELECT r.[Quick Ratio] FROM [RATIO ANALYSIS] r WHERE r.[ASX Code] like '" & ASXCODE & "';"
As a last option, use a saved with a criteria pointing to the form control (formName!controlName). This way you can test the query without VBA, as long as the form is open.
I found the solution through trial and error. When I had originally inserted the graph, under Chart Settings \ Legend I had ticked [ASX Code]. Changing this to None resolved the error message.

Open form using macro with where clause and it opens dialog box

I have an issue with "where condition" in macro on OpenForm in Access 2016.
I'm struggling with exactly the same issue, meaning a dialog window opening in between forms as in the link below:
Access- Open form with where clause
I have a condition like this in macro builder on OpenForm:
="ID_code_SC = " & [Forms]![SearchFRM_Materiel]![ID_code_SC]
and it still asks me to type the name of the ID. If I type it, it goes to a correct record.
Importantly, my ID is a text, such as ABC_01. So I modified it according to:
http://www.baldyweb.com/wherecondition.htm
and I have:
="ID_code_SC = '" & [Forms]![SearchFRM_Materiel]![ID_code_SC] & "'"
but this, on the other hand, opens an empty form and doesn't refer to any record.
I use Access 2016. I'm very new to Access and macros/VBA, so most likely I don't see some basic mistake.
Try this:
"ID_code_SC = '" & [Forms]![SearchFRM_Materiel]![ID_code_SC] & "'"

Creating an Interactive Multi Field Search Bar in MS-ACCESS

I know this is probably a simple thing I'm missing, but I'm hoping you all can help. I'm trying to add a textbox to my form that allows users to type in search criteria and have the query filter the records to only display those that qualify. The trick is I want the user to be able to type in info and have it check all the fields of the form and return records for any that are valid.
I set up a query with the fields that I want checked and I watched a few tutorials on setting criteria, but they are all working with multiple search bars. Is there a way to do it with only 1?
Like "*" Or [Forms]![Publications Page]![FilterBox] OR "*"
This is the criteria expression I wrote. It returns records just not the ones I want and doesn't seem to change after I change what is in [FilterBox]. I have 4 fields I'm running this same criteria on. All thoughts and suggestions are greatly appreciated!
Thanks!
The resulting criteria should be something like
[LastName] Like '*searchtext*' Or [FirstName] Like '*searchtext*' Or ...
So, you would have to set up a single criteria like this
Dim crit As String
crit = " Like '*" & Replace(Me!FilterBox, "'", "''") & "*' "
where the replace statement replces single (') by 2. This enables the user to enter an apostrophe in the search box.
Now you must create the whole criteria
crit = "[Field1]" & crit & "Or [Field2]" & crit & "Or [Field3]" & crit & "Or [Field4]" & crit

Function DLookup in Ms Access 2016

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. )

Errors in DLookup as a control source in access form

I have a text box with the control source of Dlookup function. But the Dlookup format makes me crazy, I tried a hundred times to refer another combo box value as criteria in Dlookup function. I got either "# name?" or "# Error".
I tried this:
=DLookUp("[Contact]","Supllier","[Company]='" & [Forms]![PurchaseOrder]![cboSupplierCompany] & "'")
and got "# Error"
when I input :
=DLookUp("[Contact]","Supllier","[Company]='" & [Me]![cboSupplierCompany] & "'")
I got "# Name?"
I finally found the solution. The right way to use Dlookup in a expression is to use the expression editor to select table field and form control.
the working expression of Dlookup in my textbox is :
DLookUp(" [Supplier]![Contact] ","Supplier"," [Supplier]![Company] ='" & [cboSupplierCompany] & "'")
Using a SQL-query window above-like versions work fine.
But they did not work in the ControlSource property setting. Here you have to use semicolons (;) instead of commas (,). At least in a German language settings environment. The control setting in German is:
Steuerelementinhalt
= DLookUp(" [Supplier]![Contact] ";"Supplier";" [Supplier]![Company] ='" & [cboSupplierCompany] & "'"