URgenteeeee Tablas Access DESDE VB
Hola me gustaria q alguien me indicase el codigo para crear una tabla desde visualbasic, pq yo lo he intentado con lo siguiente y me dice q la tabala ya existe:
sSQL1 = "CREATE TABLE Menuprincipal(Nombre TEXT)"
cnnExterna.Execute sSQL1
Donde sSQL1 lo he declarado como un String.
Por favor es muy urgente...
sSQL1 = "CREATE TABLE Menuprincipal(Nombre TEXT)"
cnnExterna.Execute sSQL1
Donde sSQL1 lo he declarado como un String.
Por favor es muy urgente...
Pues si te dice que existe es porque efectivamente existe. Hazle primero un drop table nombre_tabla y ya no te dira eso...
salu2
salu2
Graacias por todo, pero.....
El problema es q fisicamente en la base de datos no existe dicha tabla, si pongo DROP antes de crearla pues como si no borrase nada, no se cual puede ser el problema....
El problema es q fisicamente en la base de datos no existe dicha tabla, si pongo DROP antes de crearla pues como si no borrase nada, no se cual puede ser el problema....
Ya esta solucionado!!!!!!!!!!!!,era problema de la conexion a la BD. Gracias de todas formas
' This program was Written by George
' 09/01/2001
' Interactive PsyberTechnology Developers Group (IPDG3)
' Developing Products to fit all your computer needs...
' Giving you the tools to build future business today...
' For more information please visit our website for details...
' www.ipdg3.com - [email protected]
'
' Chatroom http://www.ipdg3.com/chatroom.php
' Forums http://pub52.ezboard.com/binteractivepsybertechnologydevelopersgroup
' Links http://www.ipdg3.com/links.php
' Source Code http://www.ipdg3.com/sourcecode.php
' Tutorials http://www.ipdg3.com/tutorial.php
' Contest http://www.ipdg3.com/contest.php
'
' CREATE a TABLE and DROP a TABLE with ADO
Option Explicit
Public con As New ADODB.Connection
'cmd and rs are not needed for CREATE TABLE and DROP TABLE but I put them in
'in case you wanted to expand the program.
Public cmd As New ADODB.Command
Public rs As New ADODB.Recordset
Private Sub cmdClose_Click()
'Close Connection to Database
con.Close
'Closes Program
End
End Sub
Private Sub cmdCreate_Click()
Dim stQuery As String
On Error GoTo Error
'Sets up the query CREATE TABLE to be executed in the line below
stQuery = "CREATE TABLE userinfo (RecordID INT PRIMARY KEY, firstname Text, lastname Text, emailaddress Text, comment MEMO)"
'Executes your above Query
con.Execute stQuery
Text1.Text = "CREATE TABLE userinfo in test.mdb in your app.path" & vbCrLf & vbCrLf & _
"Table Name = userinfo" & vbCrLf & _
"Field = RecordID, Type INT, PRIMARY KEY" & vbCrLf & _
"Field = firstname, Type TEXTO" & vbCrLf & _
"Field = lastname, Type TEXTO" & vbCrLf & _
"Field = emailaddress, Type TEXTO" & vbCrLf & _
"Field = comment, Type MEMO" & vbCrLf & vbCrLf & _
"Select DROP Table to DROP Table"
MsgBox "Table userinfo Created in test.mdb in your app.path" & vbCrLf & vbCrLf & _
"Field: RecordID INT PRIMARY KEY" & vbCrLf & vbCrLf & _
"Field: firstname TEXT" & vbCrLf & vbCrLf & _
"Feild: lastname TEXT" & vbCrLf & vbCrLf & _
"Field: emailaddress TEXT" & vbCrLf & vbCrLf & _
"Feild: comment MEMO", vbInformation, "TABLE userinfo CREATEd"
'Toggles between CREATE and DROP
cmdCreate.Enabled = False
cmdDrop.Enabled = True
On Error GoTo 0
cmdCreate_Exit:
Picture1.SetFocus
Exit Sub
Error:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation, "Error in [cmdCreate]"
End Sub
Private Sub cmdDrop_Click()
Dim stQuery As String
On Error GoTo Error
'Sets up the query DROP TABLE to be executed in the line below
stQuery = "DROP TABLE userinfo"
'Executes your above Query
con.Execute stQuery
Text1.Text = "TABLE userinfo DROPped" & vbCrLf & vbCrLf & _
"Select CREATE Table to CREATE Table"
MsgBox "Table userinfo has been DROPed", vbInformation, "TABLE DROPped"
'Toggles between CREATE and DROP
cmdCreate.Enabled = True
cmdDrop.Enabled = False
On Error GoTo 0
cmdDrop_Exit:
Picture1.SetFocus
Exit Sub
Error:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation, "Error in [cmdDrop]"
End Sub
Private Sub Form_Load()
On Error GoTo Error
'Opens up a connection to the database so you can execute
'CREATE TABLE and DROP TABLE Queries
With con
.Provider = "Microsoft.jet.oledb.4.0"
.ConnectionString = "data source=" & _
App.Path & "test.mdb"
.Open
End With
On Error GoTo 0
Form_Load_Exit:
Exit Sub
Error:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation, "Error in [Form_Load]"
End
End Sub
Private Sub Picture1_Click()
End Sub
' 09/01/2001
' Interactive PsyberTechnology Developers Group (IPDG3)
' Developing Products to fit all your computer needs...
' Giving you the tools to build future business today...
' For more information please visit our website for details...
' www.ipdg3.com - [email protected]
'
' Chatroom http://www.ipdg3.com/chatroom.php
' Forums http://pub52.ezboard.com/binteractivepsybertechnologydevelopersgroup
' Links http://www.ipdg3.com/links.php
' Source Code http://www.ipdg3.com/sourcecode.php
' Tutorials http://www.ipdg3.com/tutorial.php
' Contest http://www.ipdg3.com/contest.php
'
' CREATE a TABLE and DROP a TABLE with ADO
Option Explicit
Public con As New ADODB.Connection
'cmd and rs are not needed for CREATE TABLE and DROP TABLE but I put them in
'in case you wanted to expand the program.
Public cmd As New ADODB.Command
Public rs As New ADODB.Recordset
Private Sub cmdClose_Click()
'Close Connection to Database
con.Close
'Closes Program
End
End Sub
Private Sub cmdCreate_Click()
Dim stQuery As String
On Error GoTo Error
'Sets up the query CREATE TABLE to be executed in the line below
stQuery = "CREATE TABLE userinfo (RecordID INT PRIMARY KEY, firstname Text, lastname Text, emailaddress Text, comment MEMO)"
'Executes your above Query
con.Execute stQuery
Text1.Text = "CREATE TABLE userinfo in test.mdb in your app.path" & vbCrLf & vbCrLf & _
"Table Name = userinfo" & vbCrLf & _
"Field = RecordID, Type INT, PRIMARY KEY" & vbCrLf & _
"Field = firstname, Type TEXTO" & vbCrLf & _
"Field = lastname, Type TEXTO" & vbCrLf & _
"Field = emailaddress, Type TEXTO" & vbCrLf & _
"Field = comment, Type MEMO" & vbCrLf & vbCrLf & _
"Select DROP Table to DROP Table"
MsgBox "Table userinfo Created in test.mdb in your app.path" & vbCrLf & vbCrLf & _
"Field: RecordID INT PRIMARY KEY" & vbCrLf & vbCrLf & _
"Field: firstname TEXT" & vbCrLf & vbCrLf & _
"Feild: lastname TEXT" & vbCrLf & vbCrLf & _
"Field: emailaddress TEXT" & vbCrLf & vbCrLf & _
"Feild: comment MEMO", vbInformation, "TABLE userinfo CREATEd"
'Toggles between CREATE and DROP
cmdCreate.Enabled = False
cmdDrop.Enabled = True
On Error GoTo 0
cmdCreate_Exit:
Picture1.SetFocus
Exit Sub
Error:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation, "Error in [cmdCreate]"
End Sub
Private Sub cmdDrop_Click()
Dim stQuery As String
On Error GoTo Error
'Sets up the query DROP TABLE to be executed in the line below
stQuery = "DROP TABLE userinfo"
'Executes your above Query
con.Execute stQuery
Text1.Text = "TABLE userinfo DROPped" & vbCrLf & vbCrLf & _
"Select CREATE Table to CREATE Table"
MsgBox "Table userinfo has been DROPed", vbInformation, "TABLE DROPped"
'Toggles between CREATE and DROP
cmdCreate.Enabled = True
cmdDrop.Enabled = False
On Error GoTo 0
cmdDrop_Exit:
Picture1.SetFocus
Exit Sub
Error:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation, "Error in [cmdDrop]"
End Sub
Private Sub Form_Load()
On Error GoTo Error
'Opens up a connection to the database so you can execute
'CREATE TABLE and DROP TABLE Queries
With con
.Provider = "Microsoft.jet.oledb.4.0"
.ConnectionString = "data source=" & _
App.Path & "test.mdb"
.Open
End With
On Error GoTo 0
Form_Load_Exit:
Exit Sub
Error:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation, "Error in [Form_Load]"
End
End Sub
Private Sub Picture1_Click()
End Sub
