CREATE TABLE from Access

CedarTree

Registered User.
Local time
Today, 12:11
Joined
Mar 2, 2018
Messages
445
I have the following code to run sql commands as pass-throughs...

Code:
Sub subRunSQL(pSQL As String, Optional pPrint As Boolean)
On Error Resume Next

    Dim qdf As DAO.QueryDef
    Set qdf = CurrentDb.CreateQueryDef("")
    qdf.Connect = gsConnection
    qdf.sql = pSQL
    qdf.ReturnsRecords = False
    If pPrint = True Then Debug.Print pSQL
    qdf.Execute
    qdf.Close
    Set qdf = Nothing

End Sub

It generally runs without a hitch. I passed through an SQL statement to create a table (something new I'm trying). I can pass a command successfully to DROP a table. But CREATE TABLE does nothing. However, when I directly copy the sql statement and paste it into SSMS, and run it, it works fine.

Any suggestions? Thanks!
 
One suggestion is to take off the On Error Resume Next. All that does is allow errors to occur, while obfuscating them from view - this defeats the entire purpose of purposeful coding and troubleshooting (in most cases). Try running it without that and see whether it is really running "successfully".
You're creating a SQL Server table, or .. ?
 
Hi. Just a guess since we can't see your code, but maybe there's a clash if you're using quotes in your SQL statement. Can you show us the SQL statement you're using?
 
It was neither issue. It was my bad coding. I was referring to a similar, but wrong, variable in one spot. Thanks for listening anyway!
 
It was neither issue. It was my bad coding. I was referring to a similar, but wrong, variable in one spot. Thanks for listening anyway!
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom