How to execute pass-through query with long connect string in MS Access VBA

Woolf Wei 20 Reputation points
2024-03-02T09:33:45.5833333+00:00

In MS Access VBA, when I create a temp querydef object with odbc driver to run the SQL by pass-through query, a warning occur "XXX is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long"。

Then I check all the parameter settings. When I shorten the querydef.connect, it works. Then I discover the string's length of querydef.connect is limited to 255 characters.

Because I need to connect remote database server by using local SSL certifaction ,so I can't shorten the connect characters. Is there any good idea to execute the querydef with long connect string?

	Dim MyQuery as DAO.QueryDef
	Set MyQuery = CurrentDb.CreateQueryDef("")
    MyQuery.Connect = "ODBC;****"	'longer then 255 characters 
    MyQuery.SQL = "*****"	
    MyQuery.ReturnsRecords = False
    MyQuery.Execute
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
849 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Peter Doering 170 Reputation points MVP
    2024-03-09T23:47:33.8566667+00:00

    Can you use a DSN instead of the VBA assigned connection string?

    .Connect would then start "ODBC;DSN=..."

    0 comments No comments