Invalid Syntax Infinite Loop - ms-access

In the Access query builder, as I am entering a formula, if there is a syntax error, I will get the usual error message stating "The expression you entered contains invalid syntax." The problem is, when I click "OK" the message comes back again, and again, and again. It it an infinite loop and the only way I have found to get out of it is filling MS Access in the task manager. Of course I lose all my unsaved work to that point.
Also happens for other syntax errors like "The expression you entered has an invalid string."
I am attaching screenshots for reference, but please do not get hung up on the syntax. I realize the syntax is not valid, it is the infinite loop of errors that results from them that is the issue.
Sample of Error
Sample of Error #2
This has been happening for a while now. Any help anyone could provide would be most appreciated.
PS. I tried this against an empty table with the same results. So it is not a case of Access trying to validate the syntax against all records in the table.

Related

There was an error compiling this function. Access 2013 Calculated field issue

I have a table with a field which is of a calculated type and contains the following expression:
IIf(IsNull([OrderValue]),[TotalPhaseLabourCost]-[DefaultOrderValue],[TotalPhaseLabourCost]-[OrderValue])
For some reason when I go to open the table in any view it throws the error:
"There was an error compiling this function.
The Visual Basic module contains a syntax error.
Check the code, and then recompile it."
However, I have this database currently open on two laptops, one works fine and the other has this issue. I have checked both db's refs and they also match up.
That's a bit vague, so I can only make guesses.
Try to compile the code as the error message says.
check if you have any function with the same name as your field
Try replacing IIf(IsNull([OrderValue]), by IIf([OrderValue] is Null,
You probably miss the leading equal sign:
=IIf(IsNull([OrderValue]),[TotalPhaseLabourCost]-[DefaultOrderValue],[TotalPhaseLabourCost]-[OrderValue])
Or you could use:
=[TotalPhaseLabourCost]-Nz([OrderValue],[DefaultOrderValue])
For me there was some problem with some fields (it showed an error message #NAME? in some of the fields (date, number) in the 'new' record).
For me it worked to close the table, right-click it and open in design view.
For each of the fields with problems, I choose the data type (that was already shown) again from the drop down menu (so, same data type!).
Save.
Then it didn't give the error messages anymore.

Why is this error causing a loop instead of exiting the function?

I was casting around SE and the web yesterday looking for a way to concatenate specific fields from multiple records together as part of a query/report structure in my Access database. I found this SE question which led me to Allen Browne's ConcatRelated() function here. After getting off on the wrong foot by naming the module the same as the function, I got it working as desired.
However, On my initial attempt to use it in a query, I made a dumb mistake and fed it parameters that equated to "WHERE Employee = " & [Employee] instead of the correct'WHERE Employee = ' & [Employee] & "'" necessary to evaluate as a string. This resulted in the expected 3464 (data type mismatch) runtime error but with Allen's modifications it showed the actual string that caused the error. No surprise, I'll just click ok and go fix the SQL. I was surprised to find that didn't work. As soon as I clicked away the msgbox it would come back again. I used Ctrl+Break to stop the code but clicking End caused it to go right back to the same error rather than actually ending the Function. The only way I could stop the loop was by clicking Debug which drops me into the code as expected but I couldn't get out of the code to change the original Query. Hitting reset caused the error to pop again and put me right back in the loop.
I eventually got out of it by commenting everything out of the Error Handler and telling it to Exit Function. I knew that most likely was only masking the problem so I added a counter and had it increment every time the error handler was called then checked the value in the Immediate window. Sure enough, it would go up by 10 or more each time I clicked somewhere in the query.
What I don't understand is what is causing the error to loop. Err_Handler should dump it out of the function on the first error since there's nothing telling it to attempt to Resume and it specifically directs it to Exit_Handler which resets a couple variables and then does Exit Function. Even directly putting Exit Function in Err_Handler still causes multiple increments to the my error counter. Further experimenting with Debug highlights the line Set rs = DBEngine(0)(0).OpenRecordset(strSql, dbOpenDynaset). I don't know that it helps that much since it's the first line after the function constructs the value of strSql. Commenting it out caused the next line to be highlighted.
I know why caused the initial error (my mistake) and that's an easy fix. I'm more interested in the unintended result of the mistake and the loop it created.
tl;dr
What would cause this error to loop instead of exiting or breaking?
Why would it seem to occur a finite number of times if error handling calls an immediate exit but adding something like msgbox first seems to loop infinitely, or at least until I got tired of clicking.
Is there a way to circumvent this in the code so that it actually stops after the fist error?
I initially was using a table with 600+ records but then experimented further with a small table of only 10 records.
Small Table Query SELECT TestEmpHistory.Employee, ConcatRelated("EmpGroup", "TestEmpHistory", "Employee = " & Employee) AS CompliedNames
FROM TestEmpHistory to reproduce the error.
The table TestEmpHistory is in the following format:
ID(AutoNum)|Employee|EmpGroup| Other fields not referenced in the query
ID|Employee | EmpGroup|
1 |Employee1| G&A
2 |Employee1| Sales
3 |Employee2| CSR
4 |Employee2| G&A
5 |Employee3| CSR
6 |Employee3|Programming
7 |Employee3| G&A
8 |Employee4| CSR
9 |Employee4| CSR
10|Employee4| Programming
I'm using Access 2016
Without reading the whole post, I'm guessing the reason you're in a loop is because it's running this code for every row returned by the query. The only way to get out of this is, when you break into the code temporarily comment it all out so that the query can complete without generating the error for every row. Once this has completed, you can go back and correct your query design before un-commenting the function code and trying again.

Complie Error: Method or Data Member not found, but it does exist

Having a strange problem in vba access. I have a text control control called txtUserName on a form and am trying to get the contents which is all but child's play. When I try to run or complie, I get the Method or Data Member not found error. However, when I type me. Intellisense shows txtUserName. I have gone as far as copying and pasting the name from the control's properties and still get the error. What am I missing? I am completely perplexed.
Thanks in advance
Don
In this case, I was just building a SQL string. I did find the problem, there was a bad control reference, however, it was not the one that was highlighted (highlighted was the first value in an insert into string and it was actually the 3rd value)

Why am I getting "Unrecognized identifier" in my SSRS custom code?

I'm trying to make use of the custom code feature within SSRS (SQL Server Reporting Services), but keep getting an "Unrecognized identifier" message in the Expression Editor.
Here's my custom code. Actually, the final routine will be more complicated than this, but I'm trying to simplify things to figure out why the error is happening.
Public Function GetCutoffDate(batchNumber As String) As DateTime
Return New DateTime(Now.Year, 12, 31)
End Function
Here's how I reference the code in the Expression Editor.
=IIf(UCase(Fields!MailId.Value) = "VARIOUS",
Code.GetCutoffDate(Fields!BatchNumber.Value),
Fields!CutOffDate.Value)
I'm getting a red underline under the "GetCutoffDate" portion of Code.GetCutoffDate(..). Also, the message "Unrecognized identifier" appears when I hover my mouse over the "GetCutoffDate" text.
What am I missing?
I've also tried the following in the Expression Editor but keep getting the same "Unrecognized identifier" message.
=Code.GetCutoffDate(Fiels!BatchNumber.Value)
I must be overlooking something, but can't see what it is.
Thanks.
Try
Public Shared Function GetCutoffDate(batchNumber As String) As DateTime ...
in the function declaration, which has worked for me.
Turns out my custom code would still work, despite getting the "Unrecognized identifier" message. I was getting confused because the dataset I had specified was return back zero records.
Still not sure why the "Unrecognized identifier" message comes up, though. Very annoying.

object required error

Can anyone tell me the reason for this error message in report manager? My report works fine in tool. My second parameter is cascaded (derived from) to the first parameter.
When I run the report for first time it works, but when immediately change any other parameter and try to execute it gives me no data in the result and the web page shows this error:
Line: 13
Char: 692
Error: Object Required
Code: 0
Why do I receive this error?
Sounds like Javascripts version of a NullReferenceException. If that is the case, there are a billion different reasons why this could happen.