How Can I create a table by specifying tablename via inputbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tasawer
    New Member
    • Aug 2009
    • 106

    How Can I create a table by specifying tablename via inputbox

    Hi

    my application creates a table using this code:
    Code:
        strSql = "CREATE TABLE Output (Name Text, Month Number)"
        
        DoCmd.RunSQL strSql
    I need to change the table name 'Output' by a name specified via inputbox, but i'm not sure how it can be achieved.
    (something to this effect but it does not work)
    Code:
        DIM tblName As String
        DIM strSql As Strng
    
        tblName=InputBox("Table Name")
        strSql = "CREATE TABLE '" & Output & "' (Name Text, Month Number)"
        
        DoCmd.RunSQL strSql
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Code:
        tblName=InputBox("Table Name") 
        strSql = "CREATE TABLE " & tblName & " (Name Text, Month Number)"

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      You should consider adding some error handling code, in case user specifies an invalid table name, a blank string (closes inputbox wihtout typing anything) and so on.

      Comment

      • tasawer
        New Member
        • Aug 2009
        • 106

        #4
        Hi Thank you for the suggestion.

        obvioulsy my error was on using the apostrophe.

        I am confused towards using the apostrophe in sql.
        How can I know When to use it and when not to use it.

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          Our exalted leader, NeoPa, has an excellent tutorial on that very subject in the Insights section:



          Linq ;0)>

          Comment

          Working...