Search

Create Table in SQL Server using VBA


Create Table in SQL Server using VBA

Option Explicit


Sub create_SQL_Server_DB_tb()

'-----------------------------
'Thanks for downloading the code. 
'Please visit our channel for a quick explainer on this code.
'Feel free to update the code as per your need and also share with your friends.
'Channel: Youtube.com/vbaa2z
'Download free codes from http://vbaa2z.blogspot.com
'Autor: L Pamai (vbaa2z.team@gmail.com)
'-----------------------------

Dim conn As ADODB.Connection
Dim cs As String
Dim sqlcmd As String

On Error GoTo errrrrr
Set conn = New ADODB.Connection
cs = "DRIVER=SQL Server;"
cs = cs & "DATABASE=LPSQLSERVER;"
cs = cs & "SERVER=LP-PC"

conn.Open cs, "", ""

sqlcmd = "CREATE TABLE VBAA2ZdemoTb(prim_id INT IDENTITY(1,1) PRIMARY KEY,email_id Varchar(255),LastName varchar(255),FirstName varchar(255),Address varchar(255),CityCode INT, Amt_Inc Money);"

conn.Execute sqlcmd
conn.Close

Set conn = Nothing

Exit Sub
errrrrr:

Debug.Print Err.Number & ". " & Err.Description
conn.Close
Set conn = Nothing

End Sub

No comments:

Post a Comment

Note: only a member of this blog may post a comment.