ID Extracted from string not useable for connectin

2019-08-25 15:03发布

问题:

I have a linked table to a Outlook Mailitem folder in my Access Database. This is handy in that it keeps itself constantly updated, but I can't add an extra field to relate these records to a parent table.

My workaround was to put an automatically generated/added ID String into the Subject so I could work from there. In order to make my form work the way I need it to, I'm trying to create a query that takes the fields I need from the linked table and adds a calculated field with the extracted ID so it can be referenced for relating records in the form.

The query works fine (I get all the records and their IDs extracted) but when I try to filter records from this query by the calculated field I get:

This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.

I tried separating the calculated field out into three fields so it's easier to read, hoping that would make it easier to evaluate for Access, but I still get the same error. My base query is currently:

SELECT InStr(Subject,"Support Project #CS")+19 AS StartID, 
       InStr(StartID,Subject," ") AS EndID, 
       Int(Mid(Subject,StartID,EndID-StartID)) AS ID, 
       ProjectEmails.Subject, 
       ProjectEmails.[From], 
       ProjectEmails.To, 
       ProjectEmails.Received, 
       ProjectEmails.Contents
FROM ProjectEmails
WHERE (((ProjectEmails.[Subject]) Like "*Support Project [#]CS*"));

I've tried to bind a subform to this query on qryProjectEmailWithID.ID = SupportProject.ID where the main form is bound to SupportProject, and I get the above error. I tried building a query that selects all records from that query where the ID = a given parameter and I still get the same error.


The working query that adds Support Project IDs would look like:

+----+--------------------------------------+----------------------+----------------------+------------+----------------------------------+
| ID |               Subject                |          To          |         From         |  Received  |             Contents             |
+----+--------------------------------------+----------------------+----------------------+------------+----------------------------------+
|  1 | RE: Support Project #CS1 ID Extra... | questions@so.com     | Isaac.Reefman@so.com | 2019-03-11 | Trying to work out how to add... |
|  1 | RE: Support Project #CS1 ID Extra... | isaac.reefman@so.com | questions@so.com     | 2019-03-11 | Thanks for your question. The... |
|  1 | RE: Support Project #CS1 ID Extra... | isaac.reefman@so.com | questions@so.com     | 2019-03-11 | You should use a different me... |
|  2 | RE: Support Project #CS2 IT issue... | support@domain.com   | someone@company.com  | 2019-02-21 | I really need some help with ... |
|  2 | RE: Support Project #CS2 IT issue... | someone@company.com  | support@domain.com   | 2019-02-21 | Thanks for your question. The... |
|  2 | RE: Support Project #CS2 IT issue... | someone@company.com  | support@domain.com   | 2019-02-21 | Have you tried turning it off... |
|  3 | RE: Support Project #CS3 email br... | support@domain.com   | someone@company.com  | 2019-02-12 | my email server is malfunccti... |
|  3 | RE: Support Project #CS3 email br... | someone@company.com  | support@domain.com   | 2019-02-12 | Thanks for your question. The... |
|  3 | RE: Support Project #CS3 email br... | someone@company.com  | support@domain.com   | 2019-02-13 | I've just re-started the nece... |
+----+--------------------------------------+----------------------+----------------------+------------+----------------------------------+

The view in question would populate a datasheet that looks the same with just the items whos ID matches the ID of the current SupportProject record, updating when a new record is selected. A separate text box should show the full content of whichever record is selected in that grid, like this:

Have you tried turning it off and on again?

From: support@domain.com

On: 21/02/2019

Thanks for your question. The matter has been assigned to Support Project #CS2, and a support staff member will be in touch shortly to help you out. As it is considered of medium priority, you should expect daily updates.

Thanks,

Support

From: someone@company

On: 21/02/2019

I really need some help with my computer. It seems really slow and I can't do my work efficiently.

Neither of these things happens as when I try to use the calculated number to relate to the PK of the SupportProject table...


I don't know if this is a part of the problem, but whether I use Int(Mid(Subject... or Val(Mid(Subject... I still apparently get a Double, where the ID field (as an autoincrement ID) is a Long. I can't work out how to force it to return a Long, so I can't test whether that's the problem.

回答1:

So that is output resulting from posted SQL? I really wanted raw data but close enough. If requirement is to extract number after ...CS, calculate in query and save query:
Val(Mid([Subject],InStr([Subject],"CS")+2))

Then build another query to join first query to table.

SELECT qryProjectEmailWithID.*, SupportProject.tst
FROM qryProjectEmailWithID
INNER JOIN SupportProject ON qryProjectEmailWithID.ID = SupportProject.ID;

Filter criteria can be applied to either ID field.

A subform can display the related child records synchronized with SupportProject records on main form.

I tested the ID calc with your data and then with a link to my Inbox. No issue with query join.