Hi everyone,
I'm working on an Access datbase with a Microsoft SQL Server back-end.
Unfortunately we have to use a service account to connect to the back-end, so to add a bit of security I'm trying to clear each query's connection string after every time it has been used (users will have a ACCDE version of the database so they can't access the VBA code), and at the closing of the main form I have the below code to reset all connection strings in the database:
A similar sub routine is used to set up all connection strings before populating temporary tables.
The problem, however, is that when I run the DoCmd.RunSQL lines immediately after setting up all the connection strings with the sub routine (I have also tried CurrentDb.Execute), it seems that the sub routine adding all the connection strings is not fully ready before the VBA goes on with running the code that updates the temporary tables (DoCmd.RunSQL), and as a result a window pops up with "Select data source" (because the connection strings are not yet in place).
I have been experimenting a bit with adding delays before the DoCmd.RunSQL lines, but it seems the VBA code continues to execute regardless of this.
Does anyone know of a way to circumvent this problem?
Thank you
I'm working on an Access datbase with a Microsoft SQL Server back-end.
Unfortunately we have to use a service account to connect to the back-end, so to add a bit of security I'm trying to clear each query's connection string after every time it has been used (users will have a ACCDE version of the database so they can't access the VBA code), and at the closing of the main form I have the below code to reset all connection strings in the database:
Code:
Sub ClearAll_PTQ()
Dim qdf As QueryDef
For Each qdf In CurrentDb.QueryDefs
If qdf.Type = dbQSQLPassThrough Then
qdf.Connect = "ODBC;"
End If
Next
End Sub
A similar sub routine is used to set up all connection strings before populating temporary tables.
The problem, however, is that when I run the DoCmd.RunSQL lines immediately after setting up all the connection strings with the sub routine (I have also tried CurrentDb.Execute), it seems that the sub routine adding all the connection strings is not fully ready before the VBA goes on with running the code that updates the temporary tables (DoCmd.RunSQL), and as a result a window pops up with "Select data source" (because the connection strings are not yet in place).
I have been experimenting a bit with adding delays before the DoCmd.RunSQL lines, but it seems the VBA code continues to execute regardless of this.
Does anyone know of a way to circumvent this problem?
Thank you