Renaming ODBC query calls - ms-access

I have an old VB6 application which we do not have source code to edit. The application tries to open a table to a server but the table name has a period on it because the old provider allowed periods on table names. Now, we are trying to make a workaround using an MS ACCESS table. Problem is MS ACCESS do not allow periods on table names.
Our problem is that the VB6 application will request table name MAINDIR.ITEMSTABLE and it will return a TABLE NOT FOUND error because the table or query cannot be named on MS ACCESS with a period. Is there a way that we can do a VBA function that will trigger when an external ODBC call is made to the database that will see the incoming query and replace the table name? Like for example if th VB6 application sends an SQL query like:
SELECT * FROM DBNAME.TABLENAME
how can I make it refer (or modify the query) so that it returns
SELECT * FROM DBNAME_TABLENAME?
Thank you all for your help.

Related

The Microsoft Access database engine cannot find the input table or query on a local query against linked tables

I am trying to execute a SQL Select query that references linked tables in a backend database.
The query that I am trying to execute is saved as a query in the front-end database named: HourlyDistinctMonitoringDates.
HourlyDistinctMonitoringDates is defined as:
SELECT DISTINCT JobInstrumentId,
DATEVALUE(decibellog.readingdate) AS MonitoringDate,
HOUR(decibellog.readingtime) AS MonitoringHour
FROM jobinstrumentimport INNER JOIN decibellog ON jobinstrumentimport.id = decibellog.jobinstrumentimportid;
The decibellog and jobinstrumentimport tables reside in a back-end (split) database.
If I execute the HourlyDistinctMonitoringDates in a SQL View in Access from the front-end, it executes without any problem.
If I execute the SQL Command that is built by my VBA in a SQL View in Access from the front-end, it executes without any problem.
However, when I try to execute the following code; I obtain error 3078:
The Microsoft Access database engine cannot find the input table or query on a local query against linked tables...
distinctDaysAndHours = "SELECT * FROM HourlyDistinctMonitoringDates WHERE jobinstrumentid=" & rstJobInstruments!id
Set rstDistinctDatesHours = CurrentDb.OpenRecordset(distinctDatesAndHours)
When executed in VBA, the string: distinctDaysAndHours contains a SQL command such as:
SELECT * FROM HourlyDistinctMonitoringDates WHERE jobinstrumentid=10
This command will execute if pasted into the SQL View in the Access Query Design.
So the problem is obviously in the use of:
CurrentdB.OpenRecordset
The query residing in the front-end instead of the back-end.
Possibly both?
Since you have an error number, your answer is nearby
check microsoft website
https://learn.microsoft.com/en-us/office/troubleshoot/access/database-engine-not-find-input-table

JDBC:ODBC:Access "search key was not found in any record"

I have a Java Application that uses the JDBC:ODBC bridge for a connection with DBF Files linked to a Microsoft Access Database (thus, I'm using the driver for a connection to a Microsoft Access Database)
There is a table named SALFAC, that contains the following fields: NRO_FAC, COD_ITE, CAN_ITE, PRC_ITE and DSC_ITE among other columns. When I perform the following query: SELECT NRO_FAC, COD_ITE, CAN_ITE, PRC_ITE, DSC_ITE FROM SALFAC, without a WHERE clause it works fine. But when I execute the following: SELECT NRO_FAC, COD_ITE, CAN_ITE, PRC_ITE and DSC_ITE WHERE NRO_FAC=151407, my program throws a SQLException with the message The search key was not found in any record.
The NRO_FAC column is an integer type column, so using quotes results in a syntax error.
I compacted and repaired the entire database with no avail. Also, I tested the query directly on Microsoft Access 2010 and it gave me the same error. Yesterday I tested with another JDBC:ODBC bridge to the DBF files directly and also gave me the same error with the same query.
There is no blank spaces on the tables names and the columns names.
¿Is there any additional step to do in order to make queries like these work? I need execute the query with the WHERE clause. Also, for each DBF file is a NTX file. Must I do something with these files as well?
Thanks in advance
EDIT: I found something yesterday that might help. I changed the way I search the rows by inserting the entire DBF table content in an MS-Access temporary table, row by row, and then execute the query in the temprary table. It inserted the first 9 rows correctly, but the 10th row was next to a row that is marked as deleted and then the query crashed. Does the "marked-as-deleted" rows affect a query in MS-Access and/or dBase? If it does, is it possible ignore the "marked-as-deleted" rows using the JDBC:ODBC bridge? Also, must I install the Clipper commands (like DBU or PACK) in the server (it doesn't have them)?

How to run append query from data macro MS Access?

I have 2 table, one is local named 'Client' and other is a linked table to MySQL DB in my web-server named 'ClientSql'.
When I insert data into the table Client, I want it to be insert into clientSql too. I try it with data macro (after insert), but it shows me an error saying
It's not possible in linked tables.
I have tried to create an append query successfully, and it works, but it just works if I execute it manually. My question is:
Is it possible to call it from a data macro? if is possible, can you show me how? If not, can you point me to a solution?
I'm not sure why you should be able to do it manually, but not via a macro. According to this link
http://dev.mysql.com/doc/connector-odbc/en/connector-odbc-examples-tools-with-access-linked-tables.html
you should be able to do it either way.
Another thought is to eliminate the local access client table and have the access program update the mySql table directly. However, if another program is accessing the client table at the same time, this could become tricky due to multi-user and locking situations.

Automatic Information Transfer Between Databases

I have an application which uses an Access Database to store records. This application is a third party application and cannot be altered but I do have the ability to open the database and view all the records it creates.
What I would like to know is this - Is there a way to tell Access to send new records to a table in a SQL database when the record is created in Access. This needs to be done without any user intervention. In the perfect world this application would talk directly to SQL, but I would settle for a less than perfect world if the software continues to talk to Access and then Access talks to SQL.
Access 2010 did introduce event-driven data macros which behave like triggers. An After Insert data macro can create records in another local Access table, but unfortunately
Queries that contain linked tables, action queries, and database references are not allowed in data macros.
so you cannot use an After Insert data macro in Access to "push" new records into a linked SQL Server table.
However, you could use a scheduled job in SQL Server to "pull" new records from an Access database that has been set up as a Linked Server in SQL Server. For example, say we had a table named [Inquiries] in Access
ID - Autonumber (Incrementing), Primary Key
InquiryDate - Date/Time
ContactName - Text(255)
and a corresponding [dbo].[Inquiries] table in SQL Server
ID - int, Primary Key
InquiryDate - datetime
ContactName - nvarchar(255)
We could set up the Access database as a Linked Server named ACCDBDATA in SQL Server and then have SQL Server run a scheduled job every so often to pull new records from the Access database using a T-SQL statement like this
INSERT INTO dbo.Inquiries (ID, InquiryDate, ContactName)
SELECT ID, InquiryDate, ContactName
FROM ACCDBDATA...Inquiries
WHERE ID > (SELECT ISNULL(MAX(ID),0) FROM dbo.Inquiries)

Copying SQL Server query results into an Access 2010 table

Monthly, I need to get "new" data from our SQL Server business application into an Access 2010 database that contains all our "Management Reports". The Access database has a "staging table" that is to contain the raw data on which the reports are based.
I have no Access experience, but I suggested that we:
Write a query (stored proc?) on our SQL Server that returns the required raw data (...this bit was easy.)
At the end of each month, call the SQL Server stored proc from within Access 2010 (...click a button?)
Save the results of the stored proc into the staging table within Access.
But I'm finding it harder than I expected. I think I can get something ugly working using ADODB in a code-behind, looping through rows in a recordset one by one, and then setting column values one by one. But there must be a better way :)
How should I go about getting SQL Server data from Access 2010? (ADODB? DAO? QueryDesigner? other?)
Is there a "Insert Recordset Into Table" (or similar) mechanism that I can leverage?
Link the relevant sql server table or view to MS Access. Run a query against the linked table using MS Access syntax and update the staging table.
It is also possible to update an MS Access table using a connection string for SQL Server in-line in your query.
SELECT *
INTO newtable
FROM [odbc;filedsn=Z:\DSN\test.dsn].table1
Working from the SQL Server end, you can use MS Access as a linked server or run a query and update from there.
INSERT INTO
OPENDATASOURCE(
'Microsoft.ACE.OLEDB.12.0', 'Data Source=z:\docs\test.accdb')...[table1]
( atext )
SELECT atext FROM table1 WHERE id=2