Solved

Insert Into, 3134 syntax error

Posted on 2013-12-24
4
516 Views
Last Modified: 2013-12-24
I have a module I got from an EE contributor that I've been using for a while to calculated the size of each object (tables, forms etc..) in an Access DB.
I've used it many times on my Win XP Access 2003 MDB's and I'm trying to run it for the first time on my Access 2010, Win 7 Pro DB.

I'm getting a syntax error on the 'Insert Into' command.

This is the statement that throws the error:
 DoCmd.RunSQL "Insert Into ObjectSizes (Name, Type, Size) Values ('" & objName & "','" & strObject & "'," & FileLen(strDbName) - blankSize & ")"

Open in new window


I did a debug.print to see what the string it was building looked like and this is it:

Insert Into ObjectSizes (Name, Type, Size) Values ('frmConversion','Forms',135168)

Open in new window


I checked how it runs on my XP Access 2003 MDB's and it still works fine and creates exactly the same string for the 'Insert Into'

Any ideas>?
0
Comment
Question by:mlcktmguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 30

Expert Comment

by:hnasr
ID: 39738835
Check (Name, Type, Size) not to be reserved words.

Try to change table field names, as objName, objType, objSize for example.
0
 
LVL 10

Expert Comment

by:Korbus
ID: 39738842
I created an ObjectSizes table in my access 2010 DB, with those three fields, and ran the "insert into" statement you posted from debug.print, without error.
However, when I created the NAME field in the table, it gave me a "reserved word" warning, perhaps this is the problem?  Does the table already exists when you run this command?
0
 
LVL 1

Author Comment

by:mlcktmguy
ID: 39738861
Thanks for your response and Merry Christmas!

The table exists when I run the command, it is created in this subroutine.

Here is the whole subroutine:

Public Sub GetObjectSizes()
'*************************************************************************************************
' Purpose: Routine to get the sizes of tables, forms, reports and modules in the current database.
'   Usage: After running this routine, look at table ObjectSizes.
'*************************************************************************************************
    On Error GoTo CopyErr
    
    DoCmd.SetWarnings False
    
    Dim i As Integer, k As Integer, intObjectType As Integer
    Dim strObject As String, strDbName As String, objName As String
    Dim clearArr As Variant
    Dim blankSize As Long
    Dim DOC As Document
    Dim cont As Container
    Dim wsp As Workspace
    Dim db2 As Database
    Dim tdf As TableDef
    'C:\My Documents
    strDbName = "C:\My Documents\MJOTemp.mdb"
    clearArr = Array("Forms", "Reports", "Modules")  'doesn't work with Macros & queries
    
    If DCount("*", "MSysObjects", "MSysObjects.Name='ObjectSizes'") > 0 Then
        CurrentDb.TableDefs.Delete ("ObjectSizes")
    End If
    
    CurrentDb.Execute "CREATE TABLE ObjectSizes (" _
        & "Name TEXT(255), " _
        & "Type TEXT(10), " _
        & "Size LONG)"

    
    ' Return reference to default workspace.
    Set wsp = DBEngine.Workspaces(0)
   
    'Get size of blank database
    If Dir(strDbName) <> "" Then Kill strDbName
    Set db2 = wsp.CreateDatabase(strDbName, dbLangGeneral)
    db2.Close
    Set db2 = Nothing
    blankSize = FileLen(strDbName)
    Kill strDbName
    
    'Iterate to get sizes of objects (Forms, Reports, & Modules)
    For i = 0 To UBound(clearArr)
        For Each cont In CurrentDb.Containers
            If cont.Name = clearArr(i) Then
                For Each DOC In cont.Documents
                
                    'create database
                    Set db2 = wsp.CreateDatabase(strDbName, dbLangGeneral)
                    strObject = clearArr(i)
                    objName = Replace(DOC.Name, "'", "")
                    intObjectType = Switch(strObject = "Tables", 0, strObject = "Queries", 1, strObject = "Forms", 2, strObject = "Reports", 3, strObject = "Modules", 5)

                    DoCmd.TransferDatabase acExport, "Microsoft Access", strDbName, intObjectType, objName, objName
                    db2.Close
                    Set db2 = Nothing

                    DoCmd.RunSQL "Insert Into ObjectSizes (Name, Type, Size) Values ('" & objName & "','" & strObject & "'," & FileLen(strDbName) - blankSize & ")"
                    Kill strDbName
                    
                Next DOC
            End If
        Next cont
    Next i
    
    'Iterate to get sizes of tables
    For Each tdf In CurrentDb.TableDefs
        If Left(tdf.Name, 4) <> "MSys" And tdf.Attributes = 0 Then
            Set db2 = wsp.CreateDatabase(strDbName, dbLangGeneral)
            objName = Replace(tdf.Name, "'", "")
            DoCmd.TransferDatabase acExport, "Microsoft Access", strDbName, 0, objName, objName
            db2.Close
            Set db2 = Nothing

            DoCmd.RunSQL "Insert Into ObjectSizes (Name, Type, Size) Values ('" & objName & "','Tables'," & FileLen(strDbName) - blankSize & ")"
            Kill strDbName
        End If
    Next

    MsgBox "Done"
    
    DoCmd.SetWarnings True
    
    Exit Sub
    
CopyErr:
    If Err.Number = 3420 Then
        For k = 1 To 200: DoEvents: Next  'Pause needed if TransferDatabase was unsuccessful because of this error number; otherwise, database crashes database.
        Resume
    ElseIf Err.Number = 2007 Then
        MsgBox "The object " & objName & " is still open", vbInformation + vbOKOnly, strObject
    Else
        MsgBox Err.Number & vbCrLf & Err.Description
    End If
End Sub

Open in new window

0
 
LVL 30

Accepted Solution

by:
hnasr earned 100 total points
ID: 39738866
Try:
......
       & "vName TEXT(255), " _
        & "vType TEXT(10), " _
        & "vSize LONG)"
.......
Change references to field names in the rest of the code to be vName, vTypem and vSize and check.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ListData refresh onClick 5 40
Handle Apostrophes in VBA SQL - Part 2 10 40
Why can't I change data in my query? 3 30
Converting Access 2016 from 32-bit to 64-bit 8 47
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question